Skip to content

Add MapGroup #41265

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

Merged
merged 15 commits into from
Apr 25, 2022
Merged

Add MapGroup #41265

merged 15 commits into from
Apr 25, 2022

Conversation

halter73
Copy link
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
@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
Copy link
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.

Copy link
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

@davidfowl
Copy link
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
Member Author

/backport to release/7.0-preview4

@github-actions
Copy link
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