Table of Contents

Class RequestExceptionProcessorBehavior<TRequest, TResponse>

Namespace
Caesar.Pipeline
Assembly
Caesar.dll

Catches exceptions from the inner pipeline and dispatches them to the matching IRequestExceptionHandler<TRequest, TResponse, TException> instances, most specific exception type first. If a handler marks the exception as handled, its response is returned; otherwise the exception is rethrown with its original stack trace.

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

Type Parameters

TRequest

The request type.

TResponse

The response type.

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

Remarks

A handler 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 reaching any handler.

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 handler, outside the processors and every pipeline behavior: a closed handler for that request and response, whatever its exception type, or an open-generic one, which applies to every request. RequestExceptionActionProcessorStrategy sets whether it sits inside or outside RequestExceptionActionProcessorBehavior<TRequest, TResponse>. Neither the number nor the order of AddCaesar calls changes that, and handlers 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

RequestExceptionProcessorBehavior(IServiceProvider)

Creates the behavior.

public RequestExceptionProcessorBehavior(IServiceProvider serviceProvider)

Parameters

serviceProvider IServiceProvider

Provider used to resolve exception handlers.

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>