RuleFor begins a FluentValidation rule for a model property. Call it inside a validator derived from AbstractValidator<T>, select the property with a lambda, and chain requirements such as NotEmpty(), Length(), and Must(). section 32.4.1
Currency conversion rule
RuleFor(x => x.CurrencyTo) .NotEmpty() .Length(3) .Must(value => allowedValues.Contains(value)) .WithMessage("Not a valid currency code"); The chain combines several requirements for one property. Must() can also compare the selected value with the complete model, such as preventing CurrencyTo from matching CurrencyFrom. section 32.4.1
Use an extension method when a RuleFor chain contains a rule reused across validators. FluentValidation keeps these rules separate from model attributes and restricts each chain to rules that make sense for its selected property. section 32.4.1
