The [FromServices] attribute tells ASP.NET Core to provide an endpoint or handler parameter from a service registered in the dependency-injection container. It makes the binding source explicit instead of relying on framework conventions. section 7.6.2 section 16.2.3
Explicitly injecting LinkGenerator
app.MapGet("/links", ([FromServices] LinkGenerator links) => { string link = links.GetPathByName("products"); return $"View the product at {link}"; }); The handler receives LinkGenerator from dependency injection and uses it to create a product link. section 7.6.2 section 7.6.2
Minimal APIs can usually recognize registered services automatically, so adding the attribute is often unnecessary. It can improve clarity or help with some custom dependency-injection containers that do not support the conventions used by minimal APIs. section 7.6.2
app.MapGet("/links", ([FromServices] LinkGenerator links) =>
View the same LinkGenerator handler with [FromServices] applied directly to its parameter. section 7.6.2
