Skip to content

Min API Validation should skip endpoint parameters with FromServices attribute #61392

Closed
@mikekistler

Description

@mikekistler

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-validationIssues related to model validation in minimal and controller-based APIs

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions