Skip to content

Commit

Permalink
Add AddODataQueryFilter extension methods
Browse files Browse the repository at this point in the history
  • Loading branch information
xuzhg committed Nov 5, 2021
1 parent 2364e20 commit a3cba39
Show file tree
Hide file tree
Showing 7 changed files with 325 additions and 4 deletions.
69 changes: 68 additions & 1 deletion src/Microsoft.AspNetCore.OData/Microsoft.AspNetCore.OData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5932,7 +5932,7 @@
Use OData route debug middleware. You can send request "~/$odata" after enabling this middleware.
</summary>
<param name="app">The <see cref="T:Microsoft.AspNetCore.Builder.IApplicationBuilder"/> to use.</param>
<returns></returns>
<returns>The <see cref="T:Microsoft.AspNetCore.Builder.IApplicationBuilder"/>.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.ODataApplicationBuilderExtensions.UseODataRouteDebug(Microsoft.AspNetCore.Builder.IApplicationBuilder,System.String)">
<summary>
Expand Down Expand Up @@ -6213,6 +6213,27 @@
Provides extension methods to add OData services.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.ODataServiceCollectionExtensions.AddODataQueryFilter(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
Enables query support for actions with an <see cref="T:System.Linq.IQueryable" /> or <see cref="T:System.Linq.IQueryable`1" /> return
type. To avoid processing unexpected or malicious queries, use the validation settings on
<see cref="T:Microsoft.AspNetCore.OData.Query.EnableQueryAttribute"/> to validate incoming queries. For more information, visit
http://go.microsoft.com/fwlink/?LinkId=279712.
</summary>
<param name="services">The services collection.</param>
<returns>The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/> so that additional calls can be chained.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.ODataServiceCollectionExtensions.AddODataQueryFilter(Microsoft.Extensions.DependencyInjection.IServiceCollection,Microsoft.AspNetCore.Mvc.Filters.IActionFilter)">
<summary>
Enables query support for actions with an <see cref="T:System.Linq.IQueryable" /> or <see cref="T:System.Linq.IQueryable`1" /> return
type. To avoid processing unexpected or malicious queries, use the validation settings on
<see cref="T:Microsoft.AspNetCore.OData.Query.EnableQueryAttribute"/> to validate incoming queries. For more information, visit
http://go.microsoft.com/fwlink/?LinkId=279712.
</summary>
<param name="services">The services collection.</param>
<param name="queryFilter">The action filter that executes the query.</param>
<returns>The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection"/> so that additional calls can be chained.</returns>
</member>
<member name="M:Microsoft.AspNetCore.OData.ODataServiceCollectionExtensions.AddODataCore(Microsoft.Extensions.DependencyInjection.IServiceCollection)">
<summary>
Adds the core OData services required for OData requests.
Expand Down Expand Up @@ -9619,6 +9640,52 @@
<param name="nodeIn">The node to be translated.</param>
<returns>The translated node.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.QueryFilterProvider">
<summary>
An implementation of <see cref="T:Microsoft.AspNetCore.Mvc.Filters.IFilterProvider" /> that applies an action filter to
any action with an <see cref="T:System.Linq.IQueryable" /> or <see cref="T:System.Linq.IQueryable`1" /> return type
that doesn't bind a parameter of type <see cref="T:Microsoft.AspNetCore.OData.Query.ODataQueryOptions" />.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.#ctor(Microsoft.AspNetCore.Mvc.Filters.IActionFilter)">
<summary>
Initializes a new instance of the <see cref="T:Microsoft.AspNetCore.OData.Query.QueryFilterProvider" /> class.
</summary>
<param name="queryFilter">The action filter that executes the query.</param>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.QueryFilter">
<summary>
Gets the action filter that executes the query.
</summary>
</member>
<member name="P:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.Order">
<summary>
Gets the order value for determining the order of execution of providers. Providers
execute in ascending numeric value of the Microsoft.AspNetCore.Mvc.Filters.IFilterProvider.Order
property.
</summary>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext)">
<summary>
Provides filters to apply to the specified action.
</summary>
<param name="context">The filter context.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuted(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext)">
<summary>
Summary:
Called in decreasing Microsoft.AspNetCore.Mvc.Filters.IFilterProvider.Order,
after all Microsoft.AspNetCore.Mvc.Filters.IFilterProviders have executed once.
</summary>
<param name="context">The Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext.</param>
</member>
<member name="M:Microsoft.AspNetCore.OData.Query.QueryFilterProvider.IsIQueryable(System.Type)">
<summary>
Determines whether the given type is IQueryable.
</summary>
<param name="type">The type</param>
<returns><c>true</c> if the type is IQueryable.</returns>
</member>
<member name="T:Microsoft.AspNetCore.OData.Query.ApplyQueryOption">
<summary>
This defines a $apply OData query option for querying.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static IApplicationBuilder UseODataQueryRequest(this IApplicationBuilder
/// Use OData route debug middleware. You can send request "~/$odata" after enabling this middleware.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder "/> to use.</param>
/// <returns></returns>
/// <returns>The <see cref="IApplicationBuilder "/>.</returns>
public static IApplicationBuilder UseODataRouteDebug(this IApplicationBuilder app)
{
return app.UseODataRouteDebug(DefaultODataRouteDebugMiddlewareRoutePattern);
Expand Down
39 changes: 37 additions & 2 deletions src/Microsoft.AspNetCore.OData/ODataServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
// </copyright>
//------------------------------------------------------------------------------

using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.OData.Query;
using Microsoft.AspNetCore.OData.Routing;
using Microsoft.AspNetCore.OData.Routing.Parser;
Expand All @@ -22,14 +24,47 @@ namespace Microsoft.AspNetCore.OData
/// <summary>
/// Provides extension methods to add OData services.
/// </summary>
internal static class ODataServiceCollectionExtensions
public static class ODataServiceCollectionExtensions
{
/// <summary>
/// Enables query support for actions with an <see cref="IQueryable" /> or <see cref="IQueryable{T}" /> return
/// type. To avoid processing unexpected or malicious queries, use the validation settings on
/// <see cref="EnableQueryAttribute"/> to validate incoming queries. For more information, visit
/// http://go.microsoft.com/fwlink/?LinkId=279712.
/// </summary>
/// <param name="services">The services collection.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddODataQueryFilter(this IServiceCollection services)
{
return AddODataQueryFilter(services, new EnableQueryAttribute());
}

/// <summary>
/// Enables query support for actions with an <see cref="IQueryable" /> or <see cref="IQueryable{T}" /> return
/// type. To avoid processing unexpected or malicious queries, use the validation settings on
/// <see cref="EnableQueryAttribute"/> to validate incoming queries. For more information, visit
/// http://go.microsoft.com/fwlink/?LinkId=279712.
/// </summary>
/// <param name="services">The services collection.</param>
/// <param name="queryFilter">The action filter that executes the query.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddODataQueryFilter(this IServiceCollection services, IActionFilter queryFilter)
{
if (services == null)
{
throw Error.ArgumentNull(nameof(services));
}

services.TryAddEnumerable(ServiceDescriptor.Singleton<IFilterProvider>(new QueryFilterProvider(queryFilter)));
return services;
}

/// <summary>
/// Adds the core OData services required for OData requests.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
/// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns>
public static IServiceCollection AddODataCore(this IServiceCollection services)
internal static IServiceCollection AddODataCore(this IServiceCollection services)
{
if (services == null)
{
Expand Down
9 changes: 9 additions & 0 deletions src/Microsoft.AspNetCore.OData/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,7 @@ Microsoft.AspNetCore.OData.ODataOptions.UrlKeyDelimiter.set -> void
Microsoft.AspNetCore.OData.ODataOptionsSetup
Microsoft.AspNetCore.OData.ODataOptionsSetup.Configure(Microsoft.AspNetCore.OData.ODataOptions options) -> void
Microsoft.AspNetCore.OData.ODataOptionsSetup.ODataOptionsSetup(Microsoft.Extensions.Logging.ILoggerFactory loggerFactory, Microsoft.AspNetCore.OData.Routing.Parser.IODataPathTemplateParser parser) -> void
Microsoft.AspNetCore.OData.ODataServiceCollectionExtensions
Microsoft.AspNetCore.OData.ODataUriFunctions
Microsoft.AspNetCore.OData.Query.AllowedArithmeticOperators
Microsoft.AspNetCore.OData.Query.AllowedArithmeticOperators.Add = 1 -> Microsoft.AspNetCore.OData.Query.AllowedArithmeticOperators
Expand Down Expand Up @@ -964,6 +965,12 @@ Microsoft.AspNetCore.OData.Query.OrderByQueryOption.RawValue.get -> string
Microsoft.AspNetCore.OData.Query.OrderByQueryOption.Validate(Microsoft.AspNetCore.OData.Query.Validator.ODataValidationSettings validationSettings) -> void
Microsoft.AspNetCore.OData.Query.OrderByQueryOption.Validator.get -> Microsoft.AspNetCore.OData.Query.Validator.OrderByQueryValidator
Microsoft.AspNetCore.OData.Query.OrderByQueryOption.Validator.set -> void
Microsoft.AspNetCore.OData.Query.QueryFilterProvider
Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuted(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext context) -> void
Microsoft.AspNetCore.OData.Query.QueryFilterProvider.OnProvidersExecuting(Microsoft.AspNetCore.Mvc.Filters.FilterProviderContext context) -> void
Microsoft.AspNetCore.OData.Query.QueryFilterProvider.Order.get -> int
Microsoft.AspNetCore.OData.Query.QueryFilterProvider.QueryFilter.get -> Microsoft.AspNetCore.Mvc.Filters.IActionFilter
Microsoft.AspNetCore.OData.Query.QueryFilterProvider.QueryFilterProvider(Microsoft.AspNetCore.Mvc.Filters.IActionFilter queryFilter) -> void
Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption
Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.ApplyTo(object entity, Microsoft.AspNetCore.OData.Query.ODataQuerySettings settings) -> object
Microsoft.AspNetCore.OData.Query.SelectExpandQueryOption.ApplyTo(System.Linq.IQueryable queryable, Microsoft.AspNetCore.OData.Query.ODataQuerySettings settings) -> System.Linq.IQueryable
Expand Down Expand Up @@ -1530,6 +1537,8 @@ static Microsoft.AspNetCore.OData.ODataMvcBuilderExtensions.AddOData(this Micros
static Microsoft.AspNetCore.OData.ODataMvcCoreBuilderExtensions.AddOData(this Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder builder) -> Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder
static Microsoft.AspNetCore.OData.ODataMvcCoreBuilderExtensions.AddOData(this Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder builder, System.Action<Microsoft.AspNetCore.OData.ODataOptions, System.IServiceProvider> setupAction) -> Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder
static Microsoft.AspNetCore.OData.ODataMvcCoreBuilderExtensions.AddOData(this Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder builder, System.Action<Microsoft.AspNetCore.OData.ODataOptions> setupAction) -> Microsoft.Extensions.DependencyInjection.IMvcCoreBuilder
static Microsoft.AspNetCore.OData.ODataServiceCollectionExtensions.AddODataQueryFilter(this Microsoft.Extensions.DependencyInjection.IServiceCollection services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection
static Microsoft.AspNetCore.OData.ODataServiceCollectionExtensions.AddODataQueryFilter(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.AspNetCore.Mvc.Filters.IActionFilter queryFilter) -> Microsoft.Extensions.DependencyInjection.IServiceCollection
static Microsoft.AspNetCore.OData.ODataUriFunctions.AddCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, System.Reflection.MethodInfo methodInfo) -> void
static Microsoft.AspNetCore.OData.ODataUriFunctions.RemoveCustomUriFunction(string functionName, Microsoft.OData.UriParser.FunctionSignatureWithReturnType functionSignature, System.Reflection.MethodInfo methodInfo) -> bool
static Microsoft.AspNetCore.OData.Query.EnableQueryAttribute.CreateErrorResponse(string message, System.Exception exception = null) -> Microsoft.AspNetCore.Mvc.SerializableError
Expand Down
Loading

0 comments on commit a3cba39

Please sign in to comment.