SetValidator is designed to be used with non-null complex properties - any validator configured with SetValidator will be skipped if the property is null. In the case where having a null value is not valid, then you should include a NotNull check, eg:
RuleFor(x => x.Foo).NotNull().WithMessage("Please ensure Foo is not null"); RuleFor(x => x.Foo).SetValidator(new FooValidator());
Also be aware that while you can technically create inheritors of AbstractValidator for simple types (eg AbstractValidator<string>) this is not their intended usage - these should really be used for complex types as RuleFor definitions are designed to be used to be declared for properties, not the instances themselves. In this case, it would be better to declare the entire rule inline within the UserValidator:
RuleFor(x => x.Culture).NotNull().Must(c => c.Equals("nl-BE") || c.Equals("nl-FR")).WithMessage("Invalid culture");
...or, if you need this logic to be re-usable then you should extract it to an extension method:
public static class ReusableValidatorExtensions { public static IRuleBuilderOptions<T, string> EnsureValidCulture<T>(this IRuleBuilder<T, string> ruleBuilder) { return ruleBuilder.Must(c => c.Equals("nl-BE") || c.Equals("nl-FR")).WithMessage("Invalid culture"); } }
...which is then usable like this:
RuleFor(x => x.Culture).NotNull().EnsureValidCulture();
Jeremy