FluentValidator
Knowledge
- The
RuleFormethod create a validation rule.
To specify a validation rule for a particular property, call the
RuleFormethod, passing a lambda expression that indicates the property that you wish to validate.
- Rules are run syncronously
By default, all rules in FluentValidation are separate and cannot influence one another. This is intentional and necessary for asynchronous validation to work.
Must,NotNull…. are built-in validators.WithMessageis a method on a validator.Whendefines condition for validator(s).- Append multiple validators on a same property are called chaining validators.
- Chainning Validators are executed by sequence.
CascadeModecan define how these chaining validators are exectued.Continueis default which means even a validator fail, the latter validators will still be invoked.StopOnFirstFailurewill stop at the first failure of these chaining validators. Whendefines condition for validator(s)/rules.ApplyConditionTo.AllValidatorsis the default setting.ApplyConditionTo.CurrentValidatorwill make the condition only work to the preceding validator.
By default FluentValidation will apply the condition to all preceding validators in the same call to
RuleFor