-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Inferring FromServices optionality based on nullability information #39757
Copy link
Copy link
Closed
Labels
DocsThis issue tracks updating documentationThis issue tracks updating documentationbreaking-changeThis issue / pr will introduce a breaking change, when resolved / merged.This issue / pr will introduce a breaking change, when resolved / merged.feature-model-bindingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Milestone
Metadata
Metadata
Assignees
Labels
DocsThis issue tracks updating documentationThis issue tracks updating documentationbreaking-changeThis issue / pr will introduce a breaking change, when resolved / merged.This issue / pr will introduce a breaking change, when resolved / merged.feature-model-bindingold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
Type
Fields
Give feedbackNo fields configured for issues without a type.
Current design
Currently, when binding
FromServicesalways is called theServiceProviderServiceExtensions.GetRequiredService(that throws anInvalidOperationExceptionwhen the service is not found)aspnetcore/src/Mvc/Mvc.Core/src/ModelBinding/Binders/ServicesModelBinder.cs
Line 26 in 6bbd520
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.GetServiceinstead when the parameter is optional.aspnetcore/src/Http/Http.Extensions/src/RequestDelegateFactory.cs
Line 866 in 6bbd520