Class RequestExceptionProcessorBehavior<TRequest, TResponse>
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
TRequestThe request type.
TResponseThe 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
serviceProviderIServiceProviderProvider 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
requestTRequestThe request.
nextRequestHandlerDelegate<TResponse>Continues the pipeline. Not calling it short-circuits the request.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<TResponse>