Introduce IParameterBindingMetadata
to remove unbounded reflection in EndpointMetadataApiDescriptionProvider
#56587
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
area-mvc
Includes: MVC, Actions and Controllers, Localization, CORS, most templates
feature-openapi
Milestone
Background and Motivation
The
EndpointMetadataApiDescriptionProvider
is a an implementation ofIApiDescriptionProvider
that is used to generateApiDescription
instances for minimal APIs that can be used by consumers of ApiExplorer (likeMicrosoft.AspNetCore.OpenApi
) when generating descriptions of the API implementation.EndpointMetadataApiDescriptionProvider
currently relies on unbounded reflection in all scenarios (whether using minimal APIs with static code gen via RequestDelegateGenerator or dynamic code gen via RequestDelegateFactory) to resolve the following information:TryParse
method or implementsIParsable
BindAsync
[AsParameters]
attributeIt resolves this information using the existing APIs exposed in the
ParameterBindingCache
. The use of unbounded reflection in this class prevents us from making the entire OpenAPI pipeline trim friendly. To resolve this issue, we will introduce a new metadata type (IParameterBindingMetadata
) that will be inserted into endpoints by either RDG or RDF when the endpoints are compiled and used.Proposed API
Usage Examples
Alternative Designs
IParameterBindingMetadata
instance for each parameter, we could instead expose a single metadata item that allows lookup into a collection of instances using the parameter name as a key.Risks
ParameterBindingCache
for method resolution. If the parameter binding implementation for minimal APIs changes in the future, the shape of this API will have to be modified.The text was updated successfully, but these errors were encountered: