Skip to content

Inferring FromServices optionality based on nullability information #39757

Closed
@brunolins16

Description

@brunolins16

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)

Metadata

Metadata

Assignees

Labels

DocsThis issue tracks updating documentationbreaking-changeThis 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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions