Click or drag to resize

Delta validation.

This section explains the delta validation capabilities of the validation framework.

Old vs New.

The validation framework allows a validator to inspect the old and the new value/state of an entity.
This can be convenient if your business rules only allows for a certain transition from a previous to a current value/state.
During the validation process a ValidationContext is created, which contains these values, and passed to a validator for inspection.
The validator then inspects these values and decides if the context is valid. A ValidationContext contains:

  • Old value/state of the entity.

  • New value/state of the entity.

  • The state transition of the entity.

IValidator

Most of the validators only require the new value/state of the entity to decide if the context is valid. For example the MaxLengthValidator validator only checks the new string length.

State transition.

The transition property of the context expresses which transtion the value/state made. This property is an enum, named StateTransition, that defines the possible transitions.

  • Assigned: Represents a transition of a null reference or default value to an instance reference or non default value. A write operation to the container of the entity occured.

  • Removed: Represents a transition of an instance reference or non default value to a null reference or default value. A write operation to the container of the entity occured.

  • Modified: Represents a transition of an instance reference or non default value to another instance reference or non default. A write operation to the container of the entity occured.

  • Replaced: Represents a transition of a reference or value to the same reference or value. A write operation to the container of the entity occured.

  • Unchanged: Represents un untouched reference or value. No write operation to the container of the entity occured.

Most of the validators don't use the the transition property to decide if the context is valid. But for some validators this property is indispensable.
For example the ReadOnlyValidator uses this property to check that a value is not changed.