2

I'd like to use ruleSets with my FluentValidation classes when I call validateAsync, but I haven't found anything about it in the documentation, which provides examples for validate only, nor in issues of the project github repo.

With rulesets I can keep my validation rules in the same class, without rulesets I need to create validation classes for every case where I need validation for the same class.

What is the solution for this? If there is no ruleSet parameter for ValidateAsync what is the reason?

3 Answers 3

3

ValidateAsync does have a ruleSet parameter. For it to be available you need to add the FluentValidation namespace:

using FluentValidation;

Usage is like the regular (synchronous) Validate:

var validationResult = await validator.ValidateAsync(account, ruleSet: "nameOfRuleSet");
Sign up to request clarification or add additional context in comments.

Comments

1

In library Fluent validation 10 onwards.

using FluentValidation;
var validationResult = await 
validator.ValidateAsync(account,options=>options("nameOfRuleSet"));

Comments

1

In 10 versions and above

await validator.ValidateAsync(account, options => options.IncludeRuleSets("default","update"),cancellationToken);

Without a cancellation token

await validator.ValidateAsync(account, options => options.IncludeRuleSets("default","update"));

Where an update is a new ruleSet in a validator

 RuleSet("update",
    () => {
     ...
     ...
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.