Skip to content

ClassValidation internals

Jon edited this page Apr 24, 2019 · 2 revisions

ClassValidationProfile

A ClassValidationProfile gives the user the ability to define list of mappings. Each mapping is defined by type T. CreateMap returns a fluent IMappingExpression<T>. It allows users to create two types of mappings.

  1. map a property from T to an expression which takes T and an expression from IValidatorExpression.
  2. map a property from T to an expression which takes T and should return a boolean value, (basically allows a custom mapping expression)

MappingExpression

MappingExpression => ForMember can create one of two types of objects from IObjectValidator<T>

  1. ObjectValidator => used for custom mapping expressions
  2. ClassObjectValidator => used for IValidatorExpression expressions.

IValidatorExpression

IValidatorExpression gives predefined expressions for the user to consume. Each property needs to have at least one mapping, if a user doesn't want it to be used the Ignore expression should be used.

ObjectValidator

ObjectValidator takes an optional errors message string ClassObjectValidator the IValidatorExpression takes an optional error message string format text. Due to the expression func the optional param has to be passed in as null when defining a mapping.

ClassValidatorExpression

This is the guts of the predefined expressions and implements IValidatorExpression. Both the regular validator and class validation use this under the hood.

ClassObjectValidator

This class uses ClassValidatorExpression and ValidationExpressionErrorMessageFactory to take the expressions and figure out error messages.

ValidationExpressionErrorMessageFactory

The factory is used to take the method signature being used by ClassValidatorExpression expression. It returns the string predefined message or override given, to be used in the string format, as well as possible values to be used in the string format.

Clone this wiki locally