Table of Contents

Class ExceptionBehavior<TMessage, TResponse>

Namespace
Trellis.Mediator
Assembly
Trellis.Mediator.dll

Pipeline behavior that catches unhandled exceptions from handlers and converts them to Error.InternalServerError failures. This is a safety net — handlers should not throw, but if they do, this prevents unhandled exceptions from escaping the mediator pipeline.

public sealed class ExceptionBehavior<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>.

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

Constructors

ExceptionBehavior(ILogger<ExceptionBehavior<TMessage, TResponse>>)

Initializes a new instance of the ExceptionBehavior<TMessage, TResponse> class.

public ExceptionBehavior(ILogger<ExceptionBehavior<TMessage, TResponse>> logger)

Parameters

logger ILogger<ExceptionBehavior<TMessage, TResponse>>

The logger instance.

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>