Add new "MapAction" overloads#30556
Conversation
|
Hello @halter73! Because this pull request has the p.s. you can customize the way I help with merging this pull request, such as holding this pull request until a specific person approves. Simply @mention me (
|
| /// <param name="pattern">The route pattern.</param> | ||
| /// <param name="action">The delegate executed when the endpoint is matched.</param> | ||
| /// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns> | ||
| public static MapActionEndpointConventionBuilder MapGet( |
There was a problem hiding this comment.
Aren't there already Map* extension methods on route builder? Do these not colide because of Delegate parameter?
There was a problem hiding this comment.
These are overloads, but they should only be used for delegates that aren't RequestDelegates. This was also mentioned in dotnet/csharplang#4451 (comment).
| /// <param name="action">The delegate executed when the endpoint is matched.</param> | ||
| /// <param name="httpMethods">HTTP methods that the endpoint will match.</param> | ||
| /// <returns>A <see cref="IEndpointConventionBuilder"/> that can be used to further customize the endpoint.</returns> | ||
| public static MapActionEndpointConventionBuilder MapMethods( |
There was a problem hiding this comment.
Do we need this? As a user, there are alternate ways to re-use the delegate if we need to. I'm also similarly against allowing more than one HTTP attributes per MapAction delegate.
There was a problem hiding this comment.
I agree that the flexibility of delegates means that we shouldn't need to make routing metadata overly complicated. That's why I removed IRotePatternMetadata and IRouteOrderMetadata in #30563. I also stopped implementing IHttpMethodMetadata in attributes which caused multiple instances to show up on endpoints that didn't have multiple instances before. #29878 (comment)
All that said, this is an overload that already exists for RequestDelegate and any argument about reusing the Delegate, you could make for reusing the RequestDelegate. I'm just keeping it consistent by adding a Delegate overload for every RequestDelegate overload.
Fixes #30448.
By adding overloads to existing built-in IEndpointRouteBuilder extension methods, we remove the need for the routing attributes (
[HttpGet("/"],[HttpPost(..., etc.) in front of most "MapAction" methods. This will be especially handy when the methods become lambdas in non-trivial cases.This leaves
MapActionfor now. I'll have a PR that removes that andIRoutePatternMetadatasoon.