Skip to content
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

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

Closed
davidfowl opened this issue Jun 20, 2021 · 8 comments
Closed

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

davidfowl opened this issue Jun 20, 2021 · 8 comments
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-minimal-actions Controller-like actions for endpoint routing feature-routing ✔️ Resolution: Fixed The bug or enhancement requested in this issue has been checked-in!
Milestone

Comments

@davidfowl
Copy link
Member

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).
@javiercn javiercn added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates feature-routing labels Jun 20, 2021
@davidfowl davidfowl added the feature-minimal-actions Controller-like actions for endpoint routing label Jun 21, 2021
@javiercn
Copy link
Member

javiercn commented Jun 21, 2021

I might be saying the same things as you, but here are some thoughts:

  • If using a local function, automatically use that name.
  • If using a lambda, consider having an attribute [EndpointName] [RouteName] that you can apply to it.
  • You can also have a separate overload template, name, action to do this.
  • You could default to /todos/{id} as the default name, although it can get ambiguous.
  • You could also have your own addressing scheme within the link generator to address the functions that you code-generate at compile time using GetPathByAddress (with appropriate extension methods around it)

@pranavkm pranavkm added the enhancement This issue represents an ask for new feature or an enhancement to an existing one label Jun 21, 2021
@pranavkm pranavkm added this to the Backlog milestone Jun 21, 2021
@ghost
Copy link

ghost commented Jun 21, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@pranavkm
Copy link
Contributor

@davidfowl please speak to @javiercn if you need something specific for 6.0.

@davidfowl
Copy link
Member Author

Yes I'd like this for .NET 6, it's part of the minimal APIs end to end.

@ghost
Copy link

ghost commented Jun 21, 2021

Thanks for contacting us.

We're moving this issue to the Next sprint planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

@ghost
Copy link

ghost commented Jul 8, 2021

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@DamianEdwards
Copy link
Member

@davidfowl this can be closed now yes?

@davidfowl davidfowl modified the milestones: Backlog, 6.0-rc1 Sep 24, 2021
@davidfowl
Copy link
Member Author

Yep. Closing.

@davidfowl davidfowl added the ✔️ Resolution: Fixed The bug or enhancement requested in this issue has been checked-in! label Sep 24, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
@amcasey amcasey added the area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc label Jun 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates enhancement This issue represents an ask for new feature or an enhancement to an existing one feature-minimal-actions Controller-like actions for endpoint routing feature-routing ✔️ Resolution: Fixed The bug or enhancement requested in this issue has been checked-in!
Projects
None yet
Development

No branches or pull requests

6 participants