Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: Adding Info to Message when using SetValidator on child Entity

$
0
0

Hello,

when reusing a validator like here:

 

public EventValidator()
{
    var beneficiaryValidator = new BeneficiaryValidator();

   RuleFor(event => event.Beneficiary)
       .SetValidator(beneficiaryValidator)
       .When(event => event.Beneficiary != null);
}

 

I have only two options.

1- Leaving everything as is and I will get the validation messages defined in the BeneficiaryValidator

2- Chaining WithMessage and lose the validation messages defined in the BeneficiaryValidator.

 

What if I want to preserve the detailed message about the beneficiary provided by the BeneficiaryValidator while adding to the message the information about, say, the Event Id?

 

thank you very much

 

Matteo


Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>