Hooking into the new validation system #64160
-
|
The new validation system from MinimalAPIs support recursive validation of objects.
Now with the RC, I can't seem to find an easy way to use the new system. Judging by some source code, the [ValidatableType] attribute only gets considered in the context of endpoints, but not when used on arbitrary objects. So is there any way so make use of the new validation for custom objects within e.g. my own services? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Types are automatically gathered for validation by either being part of the Map* method (e.g. When you say arbitrary objects, if it's in the context of ASP.NET Core, then use |
Beta Was this translation helpful? Give feedback.
Types are automatically gathered for validation by either being part of the Map* method (e.g.
MapGet([Required] string s)) or by having the[ValidatableType]attribute on the type and the source generator running. Validation then runs as an EndpointFilter automatically by the framework.When you say arbitrary objects, if it's in the context of ASP.NET Core, then use
[ValidatableType]. If you're talking about a console app, or custom logic outside of a minimal endpoint, then you'd need to do a bit more work of registeringIValidatableInfoResolver's and calling validation yourself. Here is an example where I was playing around with calling validation myself on Hub Methods: d803d95#diff-5ebd…