Table of Contents

Class ExceptionMappingPipelineExtensions

Namespace
Microsoft.Extensions.DependencyInjection
Assembly
Excalibur.Dispatch.dll

Extension methods for adding exception mapping middleware to the pipeline.

public static class ExceptionMappingPipelineExtensions
Inheritance
ExceptionMappingPipelineExtensions
Inherited Members

Methods

UseExceptionMapping(IDispatchBuilder)

Adds exception mapping middleware to the dispatch pipeline with default configuration.

public static IDispatchBuilder UseExceptionMapping(this IDispatchBuilder builder)

Parameters

builder IDispatchBuilder

The dispatch builder.

Returns

IDispatchBuilder

The builder for fluent configuration.

Remarks

The exception mapping middleware catches all exceptions from downstream handlers and converts them to RFC 7807 Problem Details format using the registered IExceptionMapper service.

This method automatically registers the IExceptionMapper service with default configuration if not already registered. The defaults include:

  • Automatic mapping of ApiException hierarchy using ToProblemDetails()
  • Default mapper returns 500 Internal Server Error for unmapped exceptions

For custom exception mappings, use WithExceptionMapping(IDispatchBuilder, Action<IExceptionMappingBuilder>) before calling this method.

The order you call this in does not decide where the middleware runs. Position comes from the stage: this middleware is post-processing, retry and the circuit breaker are error-handling, and the pipeline composes the lower stage as the outer wrapper. Exception mapping therefore always runs outside both, whichever order you register them in. Call order decides position only among middleware sharing a stage, where it is the registration order that applies.

Every exception a handler throws reaches this middleware. Retry runs below it and decides only how many attempts a fault gets: a fault it judges permanent is abandoned after one attempt, a transient one after the configured attempts, and in both cases the original exception is left to propagate here with its type and message intact for your mapper to match on.