Implementing validation rules

All business rules must be implemented in the Business layer. Validation rules that are related to business entities can be implemented in two ways:

  • If the rule only applies to a single entity and doesn’t need to access other entities of the unit of work in order to be checked then it shall be defined in the Validation.Extensions namespace, in an extension method for the validated entity type with the following signature: Validate(fieldName : string) : IEnumerable<ValidationError>. The keepitsoftvalidationextension snippet may be used to create such a class.
  • If the rule needs to access other entities of the unit of work in order to be checked then it shall be defined in the Business.Validation namespace, in a class that implements the IValidator<TEntity> interface. For more information about this interface, please refer to the source code help file. The keepitsoftvalidator snippet may be used to create such a class.
Advertisements