Table of Contents

Class ExceptionMappingDispatchBuilderExtensions

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

Extension methods for configuring exception mapping on IDispatchBuilder.

public static class ExceptionMappingDispatchBuilderExtensions
Inheritance
ExceptionMappingDispatchBuilderExtensions
Inherited Members

Methods

WithExceptionMapping(IDispatchBuilder, Action<IExceptionMappingBuilder>)

Configures exception mapping for the Excalibur framework.

public static IDispatchBuilder WithExceptionMapping(this IDispatchBuilder builder, Action<IExceptionMappingBuilder> configure)

Parameters

builder IDispatchBuilder

The dispatch builder.

configure Action<IExceptionMappingBuilder>

Configuration action for exception mappings.

Returns

IDispatchBuilder

The builder for fluent configuration.

Remarks

This method registers exception-to-problem-details mappings that are used by the exception mapping middleware to convert exceptions to RFC 7807 Problem Details format.

Example usage:

services.AddDispatch(dispatch =>
{
    dispatch.WithExceptionMapping(mapping =>
    {
        mapping.UseApiExceptionMapping();
        mapping.Map<DbException>(ex => new MessageProblemDetails { ... });
        mapping.MapWhen<HttpRequestException>(
            ex => ex.StatusCode == HttpStatusCode.NotFound,
            ex => MessageProblemDetails.NotFound("External resource not found"));
        mapping.MapDefault(ex => MessageProblemDetails.InternalError("An unexpected error occurred."));
    });
});

Exceptions

ArgumentNullException

Thrown when builder or configure is null.