Use InferFromServicesAttribute to infer non-interface parameters in minimal actions come from services #32563
Labels
area-minimal
Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
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
Milestone
Today, the above call to
MapPost
would attempt to deserialize theApplicationDbContext
from a JSON body because there's no attribute andApplicationDbContext
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 fromDbContext
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.@ajcvickers
The text was updated successfully, but these errors were encountered: