Table of Contents

Class ValidationBehavior<TMessage, TResponse>

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll

Unified validation stage of the Trellis Mediator pipeline. Runs the compile-time IValidate contract (when the message implements it) and every IMessageValidator<TMessage> registered for TMessage in DI, aggregates all Error.UnprocessableContent failures into a single response failure, and short-circuits the pipeline before the handler is invoked.

public sealed class ValidationBehavior<TMessage, TResponse> : IPipelineBehavior<TMessage, TResponse> where TMessage : IMessage where TResponse : IResult, IFailureFactory<TResponse>

Type Parameters

TMessage

The message type.

TResponse

The response type, constrained to IResult and IFailureFactory<TSelf> so the behavior can construct typed failures without reflection.

Inheritance
ValidationBehavior<TMessage, TResponse>
Implements
IPipelineBehavior<TMessage, TResponse>
Inherited Members
Extension Methods

Remarks

The behavior runs for every message — including messages that do not implement IValidate and have no registered IMessageValidator<TMessage> — in which case it is a no-op pass-through with one DI resolve and one type test.

Failure aggregation rules:

Constructors

ValidationBehavior(IEnumerable<IMessageValidator<TMessage>>)

Unified validation stage of the Trellis Mediator pipeline. Runs the compile-time IValidate contract (when the message implements it) and every IMessageValidator<TMessage> registered for TMessage in DI, aggregates all Error.UnprocessableContent failures into a single response failure, and short-circuits the pipeline before the handler is invoked.

public ValidationBehavior(IEnumerable<IMessageValidator<TMessage>> validators)

Parameters

validators IEnumerable<IMessageValidator<TMessage>>

Remarks

The behavior runs for every message — including messages that do not implement IValidate and have no registered IMessageValidator<TMessage> — in which case it is a no-op pass-through with one DI resolve and one type test.

Failure aggregation rules:

Methods

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

public ValueTask<TResponse> Handle(TMessage message, MessageHandlerDelegate<TMessage, TResponse> next, CancellationToken cancellationToken)

Parameters

message TMessage
next MessageHandlerDelegate<TMessage, TResponse>
cancellationToken CancellationToken

Returns

ValueTask<TResponse>