-
Notifications
You must be signed in to change notification settings - Fork 10k
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
Support generating parameter validations via source generation #46349
Comments
Hi all -- We originally intended to ship this feature in .NET 9. However, due to shifting priorities and some additional requirements associated with this feature, this work is being punted to a future release. For the time being, we recommend using packages, like MiniValidation, to add validation support to your minimal APIs. While we work through all the technical details to ship a high-quality feature in a future release, we'd still appreciate your feedback to scope out the shape of the API as needed. |
I'm exploring this subject and by no mean an expert I'd suggest from a scope perspective, there are use cases as simple as a console app not using a Host, and perhaps a simple DI Service Container in support of say a CLI of some kind.
It's also a logical need to be able to inject a context with the DI Service Provider into validations equivalent to I also ran into this related discussion - dotnet/csharplang#6373 so perhaps the C# and Asp Net Core team, and others, can get together on this? |
@Simonl9l Thanks for sharing these thoughts! There have been some conversations about the possibility of generating a "common type validation source generator" based on the We've only had a few conversations about what this might look like and haven't committed to a full design yet, but the possibility of some sort of common layer for source generator-based validation engines has definitely been discussed. |
Minimal APIs doesn't currently support validations on request parameters. Ideally, this is functionality that we would be able to support by taking advantage of the endpoint filters feature introduced in .NET 7 and the existing of the
DataAnnotations
attributes.In line with the implementation of the compile-time based generator for route handler based endpoints, we want to support this functionality using a source generator. Some of this is prototyped in this repo.
The code generated for validation does the following:
Validate
overloads for each validatable parameter typeValidate
overloads for parameter types associated with complex objectsThe text was updated successfully, but these errors were encountered: