Class TypedExceptionHandlingPipelineExtensions
- Namespace
- Microsoft.Extensions.DependencyInjection
- Assembly
- Excalibur.Dispatch.dll
Extension methods for adding typed exception handling to the dispatch pipeline.
public static class TypedExceptionHandlingPipelineExtensions
- Inheritance
-
TypedExceptionHandlingPipelineExtensions
- Inherited Members
Methods
UseTypedExceptionHandling(IDispatchBuilder)
Adds TypedExceptionHandlerMiddleware to the dispatch pipeline so that ITypedExceptionHandler<TException> implementations registered in the container are resolved and invoked when a matching exception escapes a pipeline component below it.
public static IDispatchBuilder UseTypedExceptionHandling(this IDispatchBuilder builder)
Parameters
builderIDispatchBuilderThe dispatch builder.
Returns
- IDispatchBuilder
The builder for fluent configuration.
Remarks
Registering a handler in the container is not on its own sufficient: this method is what places the middleware in the pipeline. Without it, no handler is ever consulted and every exception propagates.
The middleware resolves the handler for the exception's exact type first, then walks the exception type hierarchy upward. OperationCanceledException is never routed to a handler. If no handler reports the exception as handled, it is re-thrown unchanged.
An exception thrown by the message handler itself is not routed here: the terminal dispatch stage converts it into a failed result before the pipeline unwinds. Inspect the returned result for that case.
services.AddSingleton<ITypedExceptionHandler<NotFoundException>, NotFoundExceptionHandler>();
services.AddDispatch(dispatch => dispatch.UseTypedExceptionHandling());