I have the following class
public class ValidProjectHeader : AbstractValidator
{
public ValidProjectHeader()
{
In your Validator class create a method, that includes all "common" rules that need to be applied at all times. Now you can call this method
Example
public class MyEntityValidator : AbstractValidator
{
public MyEntityValidator()
{
RuleSet("Create", () =>
{
RuleFor(x => x.Email).EmailAddress();
ExecuteCommonRules();
});
ExecuteCommonRules();
}
///
/// Rules that should be applied at all times
///
private void ExecuteCommonRules()
{
RuleFor(x => x.Name).NotEmpty();
RuleFor(x => x.City).NotEmpty();
}
}
You define the RuleSet for an action in your controller
[HttpPost]
public ActionResult Create([CustomizeValidator(RuleSet = "Create")] MyEntity model)
This will insure that requests to action Create will be validated with the RuleSet Create. All other action will use the call to ExecuteCommonRules in controller.