AspNetCoreOData
AspNetCoreOData copied to clipboard
Added support for custom query option implementation with a simple extension handler
This adds a simple IODataQueryOptionsBindingExtension interface that allows third-party libraries to extend the ApplyTo method in the ODataQueryOptions class.
Example:
Add a custom handler and extend the queryable.
public class ExampleQueryOptionsBindingExtension : IODataQueryOptionsBindingExtension
{
public IQueryable ApplyTo(IQueryable query, ODataQueryOptions queryOptions, ODataQuerySettings querySettings)
{
//Do something here
return query;
}
}
Add the extension handler to a service collection of a route component.
.AddRouteComponents("v1", model1, (services) =>
{
services.AddDataQueryOptionsBindingExtension(new ExampleQueryOptionsBindingExtension());
})
I think this is a great feature being introduced. Given that this introduces a new API, I think I'd like to see more discussions/thoughts on design considerations. @xuzhg @corranrogue9 @gathogojr any thoughts on this.
@DevKrieger is this PR linked to an existing issue? If so, could you link the issue? If not, could you create an issue that describes what the problem being solved, that feature being requested?
Before reading the code, I'd like to understand what the expected behavior, what the specification for this feature is. e.g. at what point of the query transformation pipeline is this customer handler invoked, and where does its result get applied? Is the extension expected to be able to modify the query settings and query options objects? If so, what's the impact, if not, should do we do anything to prevent that from happening?