I need some clarification on how exactly the instance whos property is being validated, is passed down to each validator in a rule.
Let's assume the following:
RuleFor(x => x.MyProperty).SetValidator(new MyCustomValidator()).NotNull();
The MyCustomValidator will set a value on MyProperty if the value is NULL in some cases.
I would expect that the NotNull validation would pass.
However, it appears this is not the case.
When I split up the RuleFor into two seperate calls:
RuleFor(x => x.MyProperty).SetValidator(new MyCustomValidator());
RuleFor(x => x.MyProperty).NotNull();
it works as expected.
But of course, i'd like to avoid having multiple "RuleFor" statements for the same property
This makes me believe that at the start of the "RuleFor", the instance and/or property value being validated is cached/copied and then provided to each validator specified for that rule.
I've also created a fiddle demonstrating this behaviour here: https://dotnetfiddle.net/rDTrDU