-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add support for filter factory to minimal APIs #40513
Copy link
Copy link
Closed
Labels
Priority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Metadata
Metadata
Assignees
Labels
Priority:1Work that is critical for the release, but we could probably ship withoutWork that is critical for the release, but we could probably ship withoutapi-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-minimal-actionsController-like actions for endpoint routingController-like actions for endpoint routingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Type
Fields
Give feedbackNo fields configured for issues without a type.
Background and Motivation
To support providing users with the ability to generate endpoint filters that target route handlers based on their method signature, we are adding support for a new "filter factory" API that allows users to access the
MethodInfoassociated with a route handler when constructing their filter.Proposed API
Introduce new
RouteHandlerFilterDelegatetype and replace instances ofFunc<RouteHandlerFilterContext, ValueTask<object?>with it.public interface IRouteHandlerFilter { - ValueTask<object?> InvokeAsync(RouteHandlerFilterContext context, Func<RouteHandlerFilterContext, ValueTask<object?>> next); + ValueTask<object?> InvokeAsync(RouteHandlerFilterContext context, RouteHandlerFilterDelegate next) }Instead of taking a list of
IRouteHandlerFilters directly, theRequestDelegateFactorynow takes in a list of delegates representing the factory in the generation.public sealed class RequestDelegateFactoryOptions { - public IReadOnlyList<IRouteHandlerFilter>? RouteHandlerFilters { get; init; } + public IReadOnlyList<Func<MethodInfo, RouteHandlerFilterDelegate, RouteHandlerFilterDelegate>>? RouteHandlerFilterFactories { get; init; } }And finally, we add a new extension method to that takes the filter factory delegates directly.
namespace Microsoft.AspNetCore.Builder; public static class RouteHandlerFilterExtensions { + public static RouteHandlerBuilder AddFilter(this RouteHandlerBuilder builder, Func<MethodInfo, RouteHandlerFilterDelegate, RouteHandlerFilterDelegate> filterFactory); }Usage Examples