Sharing validation between two models with fluent validaition
-
14-11-2019 - |
Question
I have two different models. In both models some of the validations are the same and some aren't. Is there any way to share parts of validation with fluent validation? So I don't have to maintain duplicate code.
Solution
You could use the SetValidator
method:
RuleFor(x => x.SomeComplexProperty).SetValidator(new MyValidator());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow