Skip to content

Route Group Fundamental Sample #27249

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 3 commits into from
Oct 19, 2022

Conversation

fiyazbinhasan
Copy link
Contributor

@fiyazbinhasan fiyazbinhasan commented Oct 11, 2022

Contributes to #26819

@tdykstra I accidentally removed my fork, so this PR #27177 has closed automatically. Creating a new PR.

However, it would be best if someone from the product team could intervene here. Maybe I'm missing some crucial configuration in order to make the linkGenerator work

These are very different configurations,

app.MapGroup("/{accessibility}/todos")
    .MapTodosApi()
    .WithTags("Todo Endpoints");

group.MapGet("/{id}", GetTodo).WithName("GetTodo");

With the following approach, you can't assign any name to your group. It will throw you an exception saying the name should be globally unique, hence linkGenerator won't be able to generate any links.

app.MapGroup("/public/todos")
    .MapTodosApi()
    .WithTags("Public Todo Endpoints");

app.MapGroup("/private/todos")
    .MapTodosApi()
    .RequireAuthorization();

In the sample, we should also consider showing a nested route group as well. What do you think?

@Rick-Anderson
Copy link
Contributor

@captainsafia Please review, having problem with linkGenerator

@captainsafia
Copy link
Member

@halter73 Do we happen to have a workaround for the link generation issue mentioned in #27177 or should we document it as a known issue?

@Rick-Anderson
Copy link
Contributor

@fiyazbinhasan is link generation working now?

@halter73
Copy link
Member

halter73 commented Oct 15, 2022

With the following approach, you can't assign any name to your group. It will throw you an exception saying the name should be globally unique, hence linkGenerator won't be able to generate any links.

Groups don't give you a free lunch when it comes to naming endpoints. Endpoints defined by MapGet, MapPost, etc... don't work with special RouteValuesAddress-based extension methods like GetPathByPage and GetPathByAction. It might be interesting to make these extension methods and make the key the combined RoutePattern.RawText (GetPathByRoutePattern?), but that's not something we've implemented yet.

As it stands, GetPathByName does work with MapGet, MapPost, etc... but that requires uniquely naming each endpoint using WithName or the EndpointNameAttribute which doesn't make sense on a group. This isn't a group limitation. This is just a current limitation of minimal route handlers. For now, I don't think we should demonstrate link generation in a group-focused sample.

Do we happen to have a workaround for the link generation issue mentioned in #27177 or should we document it as a known issue?

It turns out that the problem with that test was not related to groups after all. Even without the MapGroup calls, the page failed to generate a contact link. I fixed the test. dotnet/aspnetcore#44562

Copy link
Contributor

@tdykstra tdykstra left a comment

Choose a reason for hiding this comment

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

Thanks, @fiyazbinhasan

@tdykstra tdykstra merged commit fa61220 into dotnet:main Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants