Jeremy,
I too came to a need to stop before the heavier validations run. I have a few validations on properties which run very fast and then a few validations against my DB which are slow and complex. i want to skip the DB validations if any of the property validations fail.
my first thought after reading this thread was to create two rule sets. Quick validation and Slow validation. run the quick and then the slow one. skip the slow if the quick one failed. that would probably work but it would make the code less elegant.
I took a look on the code and think i have an easy proposal for implementation:
if you could add an extension that would allow me to write
i think it should be fairly easy to implement and would solve a need by many users of this great library
I too came to a need to stop before the heavier validations run. I have a few validations on properties which run very fast and then a few validations against my DB which are slow and complex. i want to skip the DB validations if any of the property validations fail.
my first thought after reading this thread was to create two rule sets. Quick validation and Slow validation. run the quick and then the slow one. skip the slow if the quick one failed. that would probably work but it would make the code less elegant.
I took a look on the code and think i have an easy proposal for implementation:
if you could add an extension that would allow me to write
//Quick validations on level 1
RuleFor(r => r.RequiredFields.Count).ForValidationLevel(1).GreaterThan(0).When(x => x.RequiredFields != null);
...
//Slow validations on level 2
RuleFor(r => r.RequiredFields.Count).ForValidationLevel(2).Must(NotHaveDuplicate);
then on your validate method where you do errors=Rules.SelectMany(Rule=>Rule.Validate) (or similar) you could just split the rules into levels, run on each level by order and then run all it's validators. fail in any validators of the current level stops the validation process.i think it should be fairly easy to implement and would solve a need by many users of this great library