Support global endpoint filters and metadata on WebApplication #59755
Labels
api-ready-for-review
API is ready for formal API review - https://github.com/dotnet/apireviews
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
Background and Motivation
In the past, there have been requests to support adding endpoint filters at the global level (see #43237). More recently, the need for global filters has emerged as part of the work to support a source generator-based validation implementation in minimal APIs (see #46349).
Endpoint filters are implemented on top of ASP.NET Core's conventions API and the
IEndpointConventionBuilder
. To support global filters, we'll need to expose an API for accessing an underlyingIEndpointConventionBuilder
on the top-levelWebApplication
.Proposed API
// Assembly: Microsoft.AspNetCore namespace Microsoft.AspNetCore.Builder; public sealed class WebApplication : IHost, IApplicationBuilder, IEndpointRouteBuilder, IAsyncDisposable { + public IEndpointConventionBuilder Conventions { get; } }
Usage Examples
Alternative Designs
Instead of exposing the
IEndpointConventionBuilder
as a property on theWebApplication
class, we can consider implementing theIEndpointConventionBuilder
interface directly on the class.However, there's hesitation around having
WebApplication
implement theIEndpointConventionBuilder
which is an interface with multiple extension methods (ref) that might pollute the API surface for theWebApplication
. Isolating these extension methods to a property keeps the Intellisense onWebApplication
clean. On the other hand, there are discoverability questions around theConventions
property.Alternatively, we can consider exposing a deconstructor on the
WebApplication
class that allows the user to pull out the underlyingIEndpointConventionBuillder
.// Assembly: Microsoft.AspNetCore namespace Microsoft.AspNetCore.Builder; public sealed class WebApplication : IHost, IApplicationBuilder, IEndpointRouteBuilder, IAsyncDisposable { + public void Deconstruct(out IEndpointConventionBuilder conventions) { } }
Risks
Conventions
comes from an implementation details of the framework and is not as familiar to users as related terms like "filter" and "metadata", which map to conventions under the hood. This might impact the discoverability of this feature.The text was updated successfully, but these errors were encountered: