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

Inferring FromServices optionality based on nullability information #39757

Closed
Tracked by #33403
brunolins16 opened this issue Jan 25, 2022 · 1 comment · Fixed by #39804
Closed
Tracked by #33403

Inferring FromServices optionality based on nullability information #39757

brunolins16 opened this issue Jan 25, 2022 · 1 comment · Fixed by #39804
Assignees
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels breaking-change This issue / pr will introduce a breaking change, when resolved / merged. Docs This issue tracks updating documentation feature-model-binding
Milestone

Comments

@brunolins16
Copy link
Member

brunolins16 commented Jan 25, 2022

Current design

Currently, when binding FromServices always is called the ServiceProviderServiceExtensions.GetRequiredService (that throws an InvalidOperationException when the service is not found)

var model = requestServices.GetRequiredService(bindingContext.ModelType);

Proposed Change

The proposal is following the same approach apply in Minimal APIs, that basically evaluates the default value and nullability context to decide if the parameter is optional or not and call the ServiceProviderServiceExtensions.GetService instead when the parameter is optional.

private static Expression BindParameterFromService(ParameterInfo parameter, FactoryContext factoryContext)

@brunolins16 brunolins16 added area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels feature-model-binding breaking-change This issue / pr will introduce a breaking change, when resolved / merged. Cost:S labels Jan 25, 2022
@brunolins16 brunolins16 added this to the .NET 7 Planning milestone Jan 25, 2022
@ghost
Copy link

ghost commented Jan 25, 2022

Thanks for contacting us.

We're moving this issue to the .NET 7 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.

@brunolins16 brunolins16 changed the title Inferring [FromServices] optionality based on nullability information Inferring FromServices optionality based on nullability information Jan 25, 2022
@brunolins16 brunolins16 added the Docs This issue tracks updating documentation label Feb 23, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-web-frameworks *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels breaking-change This issue / pr will introduce a breaking change, when resolved / merged. Docs This issue tracks updating documentation feature-model-binding
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant