-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
The source generator for Minimal API validation generates ValidatableTypeInfo objects for the types of parameters passed to endpoint handlers (with some exceptions). This currently includes parameters that are injected from the DI container. But these parameters do not come from the incoming request so do not need to be validated.
Expected Behavior
Parameters that are not part of the incoming request should be excluded from validation, and their types do not need generated validation logic. The FromServices attribute can be used to make explicit that a parameter is expected to come from the DI container, and this should be used to exclude these parameters from validation and validation code generation.
Steps To Reproduce
The "validation-from-services" project in this repo is a minimal repro of the problem:
https://github.com/mikekistler/dotnet10-issue-repros
dotnet build fails for this project because the generated validation code includes validation for IOptions<WeatherServiceOptions> and the bug reported in #61388 causes the build to fail. But if #61388 is fixed, we still need to exclude parameters coming from the DI container to eliminate unnecessary generated code and avoid unneeded processing at runtime.
Exceptions (if any)
No response
.NET Version
10.0.100-preview.3.25201.16
Anything else?
No response