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

New Post: RuleSets with two abstract validators.

$
0
0
Hi! First of all thanks for a great library.

I have an abstract validator which uses Rule sets. On of the rules looks like this:

Inside myValidator:

public class MyValidator : AbstractValidator<ObjectToValidateType>
{

      public MyValidator()
      {
                   RuleSet("BasicValidation", () => {
                         RuleFor(x => x.Limit).
                              NotNull().
                              SetCollectionValidator(new LimitValidator(_iFacilityAmountTypeBase));
			.......
                   });
		
		RuleSet(........
		
      }
}

 public class LimitValidator : AbstractValidator<BusinessAllocationDTOLimit>
 {
        public LimitValidator(IFacilityAmountTypeBase iFacilityAmountTypeBase)
        {
               RuleFor(limit => limit.Amount).GreaterThan(0);
               RuleFor(limit => limit.AmountType).NotEmpty().NotNull()
        }
 }

When i then run :
_myValidator.Validate(objectToValidate, ruleSet: "BasicValidation");
 
The validation rules inside LimitValidator are not run. They are however run if specify a rule set (BasicValidation) inside the LimitValidator.
My question is: Is there anyway to get around to not having to declare a RuleSet inside LimitValidator too? It gets really messy to declare the rule set everywhere.
If not do you have any  suggestion how this could be done in a nicer way?

Viewing all articles
Browse latest Browse all 1917

Trending Articles



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