Skip to content

Add MapGroup#41265

Merged
halter73 merged 15 commits into
mainfrom
halter73/36007
Apr 25, 2022
Merged

Add MapGroup#41265
halter73 merged 15 commits into
mainfrom
halter73/36007

Conversation

@halter73
Copy link
Copy Markdown
Member

@halter73 halter73 commented Apr 19, 2022

This PR add a new MapGroup() extension method to IEndpointRouteBuilder. This returns a new builder for defining groups of endpoints with a common prefix that implements both the IEndpointRouteBuilder and IEndpointConventionBuilder interfaces. This can be used to add endpoints with the given group prefix, and to customize those endpoints using conventions.

Sample Usage

var app = WebApplication.Create(args);

var group = app.MapGroup("/todos");
group.MapGet("/", (int id, TodoDb db) => db.ToListAsync());
group.MapGet("/{id}", (int id, TodoDb db) => db.GetAsync(id));
group.MapPost("/", (Todo todo, TodoDb db) => db.AddAsync(todo));

var nestedGroup = group.MapGroup("/{org}");
nestedGroup.MapGet("/", (string org, TodoDb db) => db.Filter(todo => todo.Org == org).ToListAsync());
nestedGroup.RequireCors("AllowAll");

// This applies to all endpoints defined on group and nestedGroup
group.RequireAuthorization();

// ...

Fixes #36007

@halter73 halter73 requested a review from a team April 19, 2022 22:06
@halter73 halter73 changed the title Add MapGroup. Add MapGroup Apr 19, 2022
Comment thread src/Http/Routing/src/Patterns/RoutePatternFactory.cs
@mkArtakMSFT mkArtakMSFT added area-runtime old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels and removed area-runtime labels Apr 20, 2022
Comment thread src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs Outdated
Copy link
Copy Markdown
Member

@davidfowl davidfowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see one test with MVC/SignalR/Health checks, something that's not the ModelDataSource.

Oh ALSO, I'd like a test that fires the change token for a data source that fires change tokens and it working.

Comment thread src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs Outdated
Comment thread src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs Outdated
Copy link
Copy Markdown
Member

@BrennanConroy BrennanConroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some comment cleanup nits

Comment thread src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs Outdated
Comment thread src/Http/Routing/src/Builder/EndpointRouteBuilderExtensions.cs Outdated
Comment thread src/Http/Routing/src/GroupRouteBuilder.cs Outdated
Comment thread src/Http/Routing/src/Patterns/RoutePatternFactory.cs Outdated
@davidfowl
Copy link
Copy Markdown
Member

Do you have a test where we call MapGroup multiple times with the same prefix? I know we're not keeping track of the prefix but it shouldn't matter unless you have duplicate routes right?

@halter73 halter73 merged commit bf03cee into main Apr 25, 2022
@halter73 halter73 deleted the halter73/36007 branch April 25, 2022 18:58
@ghost ghost added this to the 7.0-preview5 milestone Apr 25, 2022
@halter73
Copy link
Copy Markdown
Member Author

/backport to release/7.0-preview4

@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/7.0-preview4: https://github.com/dotnet/aspnetcore/actions/runs/2222446298

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve minimal api routing with grouping

5 participants