-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
builder.Services.AddDbContext<ApplicationDbContext>(
// ...
app.MapPost("/todos", (ApplicationDbContext context) => {
// ...Today, the above call to MapPost would attempt to deserialize the ApplicationDbContext from a JSON body because there's no attribute and ApplicationDbContext is a non-interface, non-TryParsable type. Adding [FromServices] to the parameter fixes the issue, but it would be nice if for certain non-interface, non-TryParsable types like types derived from DbContext were inferred to come from services by default.
One way we could do this is by looking at each parameter type and checking if that type or any of its parents have a certain attribute. Maybe we could call it InferFromServicesAttribute. Because we want libraries like EF to use this without needing to take a dependency on ASP.NET Core packages, we probably want to look for this attribute by name.