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

Use InferFromServicesAttribute to infer non-interface parameters in minimal actions come from services #32563

Closed
halter73 opened this issue May 11, 2021 · 2 comments
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

Comments

@halter73
Copy link
Member

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.

@ajcvickers

@halter73 halter73 added enhancement This issue represents an ask for new feature or an enhancement to an existing one area-runtime feature-minimal-actions Controller-like actions for endpoint routing labels May 11, 2021
@BrennanConroy BrennanConroy added this to the Next sprint planning milestone May 12, 2021
@ghost
Copy link

ghost commented May 12, 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.

@davidfowl
Copy link
Member

We're no longer doing this. Replaced by #32737 instead.

@ghost ghost locked as resolved and limited conversation to collaborators Jul 13, 2021
@rafikiassumani-msft rafikiassumani-msft added this to 6-0-rc1 All in Minimal APIs 6.0 Jul 19, 2021
@rafikiassumani-msft rafikiassumani-msft removed this from 6-0-rc1 All in Minimal APIs 6.0 Jul 19, 2021
@amcasey amcasey added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed area-runtime labels 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 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
Projects
None yet
Development

No branches or pull requests

4 participants