-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Recursive validation for Options #67548
Conversation
Tagging subscribers to this area: @dotnet/area-extensions-options Issue DetailsFixes #36093
|
I think this should be solved at a lower level. I don't think this is the correct level to solve this. If we have scenarios for Validator to validate complex types, we should fix it in System.ComponentModel.DataAnnotations. See related: |
From reading the original Issue, I was under the impression that this should be limited to |
@ajcvickers @lajones - thoughts here? This seems like a commonly requested feature in DataAnnotations. ASP.NET Blazor wants it, multiple members of the community want it here and here, and here Options validation wants it. My thinking is this should be solved in the lower level so upstack callers don't need to create multiple different solutions to this problem. cc @jeffhandley |
Pinging @SteveSandersonMS as well - since he may have some insight on how ASP.NET plans on supporting validating complex properties. |
While we're adding people, I'll bring in @DamianEdwards who's been working on a validator library recently and will likely have opinions about what our product goals should be in this area. Our current non-official solution ( |
Thanks @SteveSandersonMS. The library is MiniValidation and indeed it supports validating complex properties. It's built atop the I agree with @eerhardt that ideally we should solve this in the |
I'm happy to move this to |
@ajcvickers - thoughts? I think the original issue proposed by @pranavkm had some advantages. Namely, it doesn't recurse blindly - it only follows complex properties if the model author opts-in to the complex property being validated as well. |
@eerhardt if we wish to have these changes be consumable by frameworks like ASP.NET Core MVC, Blazor, etc. then requiring the attribute might make that difficult as existing models won't have it. Perhaps we could consider APIs for both patterns, i.e. default mode which only recurses if attribute is found, opt-in mode that enables recursion at the call site (or forcibly disables it even ignoring the attribute if found). It would be nice to consider a simpler calling pattern too while we're looking at this part of the framework. |
My thinking was that it is the model author that decides what should and shouldn't be validated. It isn't really up to ASP.NET MVC or Blazor, is it? The frameworks just say "validate this object", and the object's attributes are what declares what should and shouldn't be validated.
That was my intention. The behavior is the same until the model is updated to say "drill into this property and validate it as well". |
@eerhardt my point was these frameworks already do recursive validation of complex properties today, without the attribute, and that if we update |
Closing this PR as per conversation above. Will take this on in the issue page and relabed to |
@maryamariyan @eerhardt @SteveSandersonMS @DamianEdwards - new PR with this moved down to |
Fixes #36093