-
Notifications
You must be signed in to change notification settings - Fork 9.8k
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
Setting route order imperatively #47579
Comments
@Tratcher Could I send a PR for this when the API got 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:
|
It's very evident from reading the code that they went out of their way not to expose Personally, I like making it easy to override endpoints if you want to using order. I've written the workaround code a number of times myself, but maybe it's a footgun. |
I don't see an issue with this API. |
Aside from being a footgun (it definitely is), order can have a surprising impact on performance for a really big route table. Those are some of the reasons why didn't make it obvious how to use order. You shouldn't need it that often. No concerns here, if the question comes up often then it should be made easier. |
What are scenarios where this would be used? In this issue - #39241 - there are two ambiguous routes, and setting the order means one will never be called. I wonder why someone would want to do that. Could |
API Review Notes:
API Approved. Let's make sure we throw for non- namespace Microsoft.AspNetCore.Builder;
public static class RoutingEndpointConventionBuilderExtensions
{
+ public static TBuilder WithOrder<TBuilder>(this TBuilder builder, int order) where TBuilder : IEndpointConventionBuilder;
} |
@Kahbazi This is ready, want to send a PR now? |
Background and Motivation
People frequently ask how to change a route's order. Today this is only easy with attribute routing, not minimal APIs.
The workaround is:
app.Map("/api/v1/users", emptyDelegate).Add(static builder => ((RouteEndpointBuilder)builder).Order = 1);
This comes up in YARP, migrations, internal customers, and external: #39241.
Proposed API
namespace Microsoft.AspNetCore.Builder; public static class RoutingEndpointConventionBuilderExtensions { + public static TBuilder WithOrder<TBuilder>(this TBuilder builder, int order) where TBuilder : IEndpointConventionBuilder; }
Usage Examples
Alternative Designs
Risks
Not all routes support order. This would throw when used on a builder that didn't cast to RouteEndpointBuilder.
@danroth27
The text was updated successfully, but these errors were encountered: