Closed
Description
Background and Motivation
This would allow unattributed methods to disambiguate between route and query string when the method parameters are unattributed. Today we generate code that prefers route over query string and we could avoid that in certain cases. It would also allow us to better fail if the user used [FromRoute]
and there was no route parameter with that name defined.
Proposed API
Since our overloads are getting a bit crazy with this change, I suggest we add an options object to handle the overflow.
public static class RequestDelegateFactory
{
- public static RequestDelegate Create(Delegate action, IServiceProvider? serviceProvider)
+ public static RequestDelegate Create(Delegate action, Func<HttpContext, object>? targetFactory = null, RequestDelegateFactoryOptions? options = null)
- public static RequestDelegate Create(MethodInfo methodInfo, Func<HttpContext, object>? targetFactory = null, IServiceProvider? serviceProvider)
+ public static RequestDelegate Create(MethodInfo methodInfo, Func<HttpContext, object>? targetFactory = null, RequestDelegateFactoryOptions? options = null)
}
+ public class RequestDelegateFactoryOptions
+ {
+ public IServiceProvider? ServiceProvider { get; init; }
+ public IReadOnlyList<string>? RouteParameterNames { get; init; }
+ }
Usage Examples
var options = new RequestDelegateFactoryOptions
{
ServiceProvider = serviceProvider,
RouteParameterNames = new[] { "id" }
};
var rd = RequestDelegateFactory.Create((int id) => id, options: options);
Alternative Designs
A single static method with optional parameters.
public static class RequestDelegateFactory
{
+ public static RequestDelegate Create(MethodInfo methodInfo, Func<HttpContext, object>? targetFactory = null, IServiceProvider? serviceProvider = null, IReadOnlyList<string>? routeParameterNames = null);
}
Risks
None