ASP.NET Core › Dependency Injection

How does dependency injection integrate with minimal API endpoint handlers versus controller constructors?

Advanced

Answer

Controllers exclusively use constructor injection, resolving all dependencies once when the controller instance is created per-request. Minimal API endpoint handlers instead inject services directly as delegate parameters, automatically inferred as coming from DI (rather than route/body binding) for registered service types -- letting each individual endpoint declare exactly the specific dependencies it needs without a shared constructor.
// Controller: constructor injection
public class ProductsController(IProductService service) : ControllerBase {
    [HttpGet] public IActionResult GetAll() => Ok(service.GetAll());
}

// Minimal API: parameter injection, inferred automatically
app.MapGet("/products", (IProductService service) => service.GetAll());
Real-world example A minimal API's simple GET endpoint declares only IProductService as a dependency, while a more complex POST endpoint additionally declares ILogger, avoiding the controller pattern's tendency to inject dependencies into a shared constructor not every action uses.

Common follow-ups: Does parameter-based injection have any measurable performance difference from constructor injection?;How does explicit [FromServices] disambiguate a service parameter from a route/body parameter?