-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Update Endpoint metadata providers to include EndpointBuilder param #43125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes:
API Rejected! (unless we find an easy way to do this in MVC) |
Okay. I think this is workable. But we also need to add a new API to RDF to allow namespace Microsoft.AspNetCore.Http.Metadata;
public interface IEndpointMetadataProvider
{
- static abstract void PopulateMetadata(EndpointMetadataContext context);
+ static abstract void PopulateMetadata(MethodInfo method, EndpointBuilder builder);
}
public interface IEndpointParameterMetadataProvider
{
- static abstract void PopulateMetadata(EndpointParameterMetadataContext parameterContext);
+ static abstract void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder);
}
- public sealed class EndpointMetadataContext
- {
- public EndpointMetadataContext(MethodInfo method, IList<object> endpointMetadata, IServiceProvider applicationServices);
- public MethodInfo Method { get; }
- public IList<object> EndpointMetadata { get; }
- public IServiceProvider ApplicationServices { get; }
- }
- public sealed class EndpointParameterMetadataContext
- {
- public EndpointParameterMetadataContext(ParameterInfo parameter, IList<object> endpointMetadata, IServiceProvider applicationServices);
- public ParameterInfo Parameter { get; }
- public IList<object> EndpointMetadata { get; }
- public IServiceProvider ApplicationServices { get; }
- }
namespace Microsoft.AspNetCore.Http;
+ public sealed class RequestDelegateMetadataResult
+ {
+ public required IReadOnlyList<object> EndpointMetadata { get; init; }
+ }
public static class RequestDelegateFactory
{
+ public static RequestDelegateMetadataResult InferMetadata(MethodInfo methodInfo, RequestDelegateFactoryOptions? options = null);
} |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
API Review Notes:
On a personal note, I would much prefer to use |
Cross-refing #43330 as a scenario for this API. |
Description of the order metadata is added. Order of Metadata addition today
Order of Metadata addition tomorrow
There is a subtle behavior where metadata is not re-added only if the options is reused between InferMetadata() and Create().
namespace Microsoft.AspNetCore.Http.Metadata;
public interface IEndpointMetadataProvider
{
- static abstract void PopulateMetadata(EndpointMetadataContext context);
+ static abstract void PopulateMetadata(MethodInfo method, EndpointBuilder builder);
}
public interface IEndpointParameterMetadataProvider
{
- static abstract void PopulateMetadata(EndpointParameterMetadataContext parameterContext);
+ static abstract void PopulateMetadata(ParameterInfo parameter, EndpointBuilder builder);
}
- public sealed class EndpointMetadataContext
- {
- public EndpointMetadataContext(MethodInfo method, IList<object> endpointMetadata, IServiceProvider applicationServices);
- public MethodInfo Method { get; }
- public IList<object> EndpointMetadata { get; }
- public IServiceProvider ApplicationServices { get; }
- }
- public sealed class EndpointParameterMetadataContext
- {
- public EndpointParameterMetadataContext(ParameterInfo parameter, IList<object> endpointMetadata, IServiceProvider applicationServices);
- public ParameterInfo Parameter { get; }
- public IList<object> EndpointMetadata { get; }
- public IServiceProvider ApplicationServices { get; }
- }
namespace Microsoft.AspNetCore.Http;
+ public sealed class RequestDelegateMetadataResult
+ {
+ public RequestDelegateMetadataResult();
+ public required IReadOnlyList<object> EndpointMetadata { get; init; }
+ }
public static class RequestDelegateFactory
{
+ public static RequestDelegateMetadataResult InferMetadata(MethodInfo methodInfo, RequestDelegateFactoryOptions? options = null);
- public static RequestDelegateResult Create(Delegate handler, RequestDelegateFactoryOptions? options = null);
+ public static RequestDelegateResult Create(Delegate handler, RequestDelegateFactoryOptions? options);
+ public static RequestDelegateResult Create(Delegate handler, RequestDelegateFactoryOptions? options = null, RequestDelegateMetadataResult? metadataResult = null);
- public static RequestDelegateResult Create(MethodInfo methodInfo, Func<HttpContext, object>? targetFactory = null, RequestDelegateFactoryOptions? options = null)
+ public static RequestDelegateResult Create(MethodInfo methodInfo, Func<HttpContext, object>? targetFactory, RequestDelegateFactoryOptions? options);
+ public static RequestDelegateResult Create(MethodInfo methodInfo, Func<HttpContext, object>? targetFactory = null, RequestDelegateFactoryOptions? options = null, RequestDelegateMetadataResult? metadataResult = null);
} API Approved! |
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
|
@halter73 seems this should this be moved to rc.2? |
Background and Motivation
With #43000, we've approved adding
RequestDelegateFactoryOptions.EndpointBuilder
andEndpointFilterFactoryContext.EndpointBuilder
so filters can get full access to more metadata like theRoutePattern
(with a downcast) andDisplayName
.I think
IEndpointMetadataProvider
andIEndpointParameterMetadataProvider
deserve the same treatment.Also see #42827 (comment) for more context.
Proposed API
Usage Examples
Alternative Designs
We could change context. to reference a builder in case we want to add more parameters in the future that are not on the
EndpointBuilder
in some way. I find this is clunky though, and I'm not sure how likely additional future parameters really are.Risks
With the primary proposal, we lose out on having a context, so it's harder to add parameters in the future if we find it will be necesarry.
Third-party
IEndpointMetadataProvider
implementations need to rewrite theirPopulateMetadata
methods with either change, but it should be pretty mechanical.@DamianEdwards
The text was updated successfully, but these errors were encountered: