Skip to content

ValidationBehavior<TMessage, TResult> class

Namespace: Vitreous.FluentValidation.Behaviors
Assembly: Vitreous.FluentValidation.dll

Pipeline behavior that runs every registered IValidator<T> for a command or query before its handler. When validation fails the handler is not called, and the dispatch returns Validation with the failures grouped by property name.

public sealed class ValidationBehavior<TMessage, TResult> : IPipelineBehavior<TMessage, TResult>

TMessage

TResult

object ← ValidationBehavior<TMessage, TResult>

IPipelineBehavior<TMessage, TResult>

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Messages without a validator pass straight through. Void commands run through this behavior too, with TResult = Unit. Validators run one after another, and every failure from every validator is reported.

ValidationBehavior(IEnumerable<IValidator<TMessage>>)

Section titled “ ValidationBehavior(IEnumerable<IValidator<TMessage>>)”
public ValidationBehavior(IEnumerable<IValidator<TMessage>> validators)

validators IEnumerable<IValidator<TMessage>>

Handle(TMessage, MessageHandlerDelegate<TMessage, TResult>, CancellationToken)

Section titled “ Handle(TMessage, MessageHandlerDelegate<TMessage, TResult>, CancellationToken)”

Executes this behavior step, calling next to continue the pipeline.

public ValueTask<Result<TResult>> Handle(TMessage message, MessageHandlerDelegate<TMessage, TResult> next, CancellationToken ct = default)

message TMessage

next MessageHandlerDelegate<TMessage, TResult>

ct CancellationToken

ValueTask<Result<TResult>>