A named validation is named validator for a given type. Named validations can be invoked on objects by using their names. The following section shows creating and using named validations as well as saving named validations (in memory) for later use.

            // Create a named validation for Person
// Setup rules for the validation inside the setup method
var validation = new Validation<Person>("My_Person_Validation")
.Setup(v => v.IsNotNull(p => p.Name, "Name is mandatory.")
.IsGreaterThan(18, p => p.Age, "Age should be greater than 18.")
);

// Get a validation repository. You can create your own validation repositories or use the included ValidationRepository which is an in-memory repository
var validationRepository = new ValidationRepositoryFactory().GetValidationRepository();
validationRepository.Save(validation);

// Validate a person object using the named validation
var invalidPerson = new Person();
var validator = invalidPerson.ValidateUsing("My_Person_Validation");
Assert.IsFalse(validator.IsValid);


Notes on Named Validations: