Skip to content

Add easier way to name endpoints for easier link generation #33687

@davidfowl

Description

@davidfowl

Today it's possible to use the LinkGenerator to generate links to arbitrary endpoints but it's a little inconvenient to do this for endpoints that exists outside of MVC because they don't have intrinsic names or route values (like "controller" and "action").

Here's an example of what this looks like this today:

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();

app.MapGet("/", (LinkGenerator linkGenerator) =>
{
    return linkGenerator.GetPathByName("todos", values: new { id = 13 });
});

app.MapGet("/todos/{id}", (int id) => { }).WithMetadata(new EndpointNameMetadata("todos"));

app.Run();

Some ideas:

  • We add an extension method WithName to hide the explict metadata addition.
  • Automatically infer some defaults based on route template.
  • Automatically infer some defaults based on method name (if not compiler generated).

Metadata

Metadata

Assignees

No one assigned

    Labels

    ✔️ Resolution: FixedThe bug or enhancement requested in this issue has been checked-in!area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesenhancementThis issue represents an ask for new feature or an enhancement to an existing onefeature-minimal-actionsController-like actions for endpoint routingfeature-routing

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions