I am new to Fluent Validation and just got version 5.3 from nu Get it yesterday. I am trying to apply an existing validator (PhoneValidator) to a collection property (ICollection) of a class (Employee). The Fluent Validator documentation says:
RuleFor(x => x.Orders).SetCollectionValidator(new OrderValidator());
However, the SetCollectionValidator () method is not available in the version I have. Instead, there is only SetValidator () , which is marked as [deprecated] . I saw other posts regarding the same situation and found out that SetCollectionValidator () is an extension method and must be sure that FluentValidation is imported. I do.
What am I missing here?
using FluentValidation;
using FluentValidation.Validators;
public class EmployeeValidator : AbstractValidator<Employee>
{
public EmployeeValidator()
{
RuleFor(e => e.PhoneNumbers).SetCollectionValidator(new PhoneValidator());
}
}
public class PhoneValidator : AbstractValidator<Phone>
{
public PhoneValidator()
{
RuleFor(e => e.Number).Length(10).Matches("^[0-9]$");
}
}