-
Notifications
You must be signed in to change notification settings - Fork 4
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
Discussion: Model Validation #335
Comments
Yeah, generally great idea. The problem - as always - is in the details. Historically we had a lot of more validation going on but back then we did it just wrong instead of right. I think to some degrees in the "older" models this wrong validation approach is still in the code today. We used the Required-Attriubtes (and wild wild methods called on deserialization) from our JSON-Framework to validate single models. Meaning: You could not (de)serialize anything where e.g. certain properties weren't set. The validation and the serialization were coupled to each other. it was annoying for a couple of reasons:
The thing with a validation is: how could you in this library foresee which validations are actually relevant to different users and use cases? Maybe in someones use case connecting a Malo from Gas with a MeLo from Strom is actually a valid data constellation. So I wouldn't like to go back to mandatory validation here. My suggestion would be: Build your own composite models and write your own validations for those. public class MyCompositeFoo : IValidatableObject
{
public Messlokation MeLo {get;set;}
public Marktlokation MaLo {get;set;}
public IEnuerable<ValidationResult> Validate(...)
{
}
} BTW: There is an old ticket from 3 years ago, that has the same idea as you: #33 |
Get your point! Thanks for your response! |
Hi there!
Am I the only one who would appreciate the models to implement some kine of model validation options?
Stumbled upon IValidatableObject - wouldn't it be nice to have that?
I stumbled upon an issues in our system where a Marktlokation contained a Messlokation with a different Sparte than the Marktlokation itself. Such logical restrictions could easily be enforced with such an universal validation mechanis as provided with the IValidatableObject interface.
Let me know what you think!
BR
Gabriel
The text was updated successfully, but these errors were encountered: