Table of Contents

Class RequestExceptionActionProcessorBehavior<TRequest, TResponse>

Namespace
Caesar.Pipeline
Assembly
Caesar.dll

Runs every matching IRequestExceptionAction<TRequest, TException> when the inner pipeline throws, most specific exception type first, then rethrows the original exception.

public sealed class RequestExceptionActionProcessorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse> where TRequest : notnull

Type Parameters

TRequest

The request type.

TResponse

The response type.

Inheritance
RequestExceptionActionProcessorBehavior<TRequest, TResponse>
Implements
IPipelineBehavior<TRequest, TResponse>
Inherited Members

Remarks

An action that fails, synchronously or asynchronously, does not stop the remaining actions and does not replace the original exception, which is always rethrown with its original stack trace. The failures are attached to the original exception's Data under the key "Caesar.ExceptionActionFailures" as an IReadOnlyList<T> of Exception, in the order the actions ran; failures from a nested Send that already attached the key come first. The list keeps the 16 most recent failures, so an exception instance that several sends share (a cached failure) does not collect them without bound.

An action class that implements the interface for several types in the exception's hierarchy runs once, for the most specific of them; several registrations of one class for the same type all run. With BypassExceptionHandlingOnCallerCancellation set, an OperationCanceledException thrown while the caller's cancellation token is cancelled is rethrown without running any action.

This stage is not registered as an IPipelineBehavior<TRequest, TResponse>. In a container set up with AddCaesar, the mediator composes it into the pipeline of each request type that has an exception action, outside the processors and every pipeline behavior: a closed action for that request, whatever its exception type, or an open-generic one, which applies to every request. RequestExceptionActionProcessorStrategy sets whether it sits outside or inside RequestExceptionProcessorBehavior<TRequest, TResponse>. Neither the number nor the order of AddCaesar calls changes that, and actions registered after AddCaesar count too. If this behavior is registered as a pipeline behavior anyway, the mediator leaves its own stage out, so it runs once, at that registration's position.

Constructors

RequestExceptionActionProcessorBehavior(IServiceProvider)

Creates the behavior.

public RequestExceptionActionProcessorBehavior(IServiceProvider serviceProvider)

Parameters

serviceProvider IServiceProvider

Provider used to resolve exception actions.

Methods

Handle(TRequest, RequestHandlerDelegate<TResponse>, CancellationToken)

Handles the request, calling next to continue the pipeline.

public Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)

Parameters

request TRequest

The request.

next RequestHandlerDelegate<TResponse>

Continues the pipeline. Not calling it short-circuits the request.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<TResponse>