-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
Add API to turn delegate or MethodInfo into a RequestDelegate #31181
Comments
We should expose this building block. I see no reason to be overly prescriptive and make it difficult for developers to get at this RequestDelegate. We shouldn't assume we can think of all the ways developers might possibly want to use it. If we don't expose this, people will do hacks like build a whole middleware pipeline just to get at a RequestDelegate. We don't technically need all of these overloads. If we do decide to reduce the overloads, |
I think it's too difficult. I tried it but happy to be proven wrong here. |
I haven't tried it yet, but I believe you. Adding the attributes back to the generated I do like all 3 overloads. I'm adding the |
Will there be a way to have the framework pick these up via reflection? A bit like services.AddControllers() detects all controllers in the assembly. Maybe marking the "special" methods with an attribute? Thanks, |
@mumby0168 explicitly no. No scanning will be done by default to discover these, we already have that framework (mvc). This building blocking can be used to build that sort of thing if you want but we won’t be building that again. |
Is there a way to get access to the |
Yep. Just add an aspnetcore/src/Http/Routing/src/Internal/MapActionExpressionTreeBuilder.cs Lines 143 to 146 in 5189524
|
Part of me is wondering if this is more of a factory than a builder? |
That's a good point. I'll change it to |
Background and Motivation
MVC Controllers have this magic power baked inside of them to allow dispatching HTTP requests to an arbitrarily shaped method on a controller (called actions). As part of the work to make this more accessible, we want to expose a zero dependency building block from lower in the stack that enables the same thing with arbitrary methods and delegates. This lets library authors build convenient and complex request handling logic without having to take big dependencies on controllers or mvc.
Proposed API
Usage Examples
There are 2 scenarios
Enhanced routing (MapAction) with is number 1, MVC controllers are examples of number 2.
2a. Class dispatch with instance
2a. Class dispatch with static
Alternatives
Don't expose this building block and expose it on more places. Middleware, Routing, IApplicationBuilder etc.
PS: We might also need to consider options that control behavior in the future.
cc @pranavkm
The text was updated successfully, but these errors were encountered: