Skip to content

Endpoint names are not inferred #27424

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

Closed
wants to merge 3 commits into from
Closed

Conversation

halter73
Copy link
Member

This was the behavior in some .NET 6 preview releases, but was reverted in .NET 6 RC 2 due to potential uniqueness issues given overloaded method groups: dotnet/aspnetcore#36518. This is why {linker.GetPathByName("Hi", values: null)} was null.

It's surprising that this REVIEW note stayed in the doc for over a year without anyone who knows about this noticing, but that's partially on me.

Also, these are technically "endpoint" names, not "route" names.


Routes can be given names in order to generate URLs to the route. Using a named route avoids having to hard code paths in an app:
Endpoints can be given names in order to generate URLs to the endpoint. Using a named endpoint avoids having to hard code paths in an app:
Copy link
Member

Choose a reason for hiding this comment

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

Endpoints can be given names in order to generate URLs to the endpoint.

This sentence feels a little confusing. What exactly are we trying to say here?

Copy link
Member Author

Choose a reason for hiding this comment

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

That endpoint names provide some indirection when generating links? I didn't write this originally, so I'm guessing. Do you have a suggestion for how we should reword this?

Copy link

@mauler2025 mauler2025 Mar 7, 2023

Choose a reason for hiding this comment

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

Providing the readers with a lot of examples makes it much clearer. :-)

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

var users = new List<User>
 {
    new User(1,"A"),
    new User(2,"B"),
    new User(3,"C"),
 };

IResult GetUser(int id)
{
    return users.Find(u => u.id == id) is User user ?
        TypedResults.Ok(user) : TypedResults.NotFound();
}

IResult CreateUser(User user, LinkGenerator lg)
{
    users.Add(user);
    var path = lg.GetPathByName(nameof(GetUser), new { id = user.id })!;
    return TypedResults.Created(path, user);
}

var group = app.MapGroup("/users");

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

group.MapPost("/", CreateUser);

app.Run();

record class User(int id, string name);

Co-authored-by: Safia Abdalla <safia@microsoft.com>
@halter73
Copy link
Member Author

halter73 commented Nov 1, 2022

Replaced by #27458.

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.

3 participants