Table of Contents

Class TrellisAspOptions

Namespace
Trellis.Asp
Assembly
Trellis.Asp.dll

Configuration options for Trellis ASP.NET Core integration. Controls how domain error types are mapped to HTTP status codes.

public sealed class TrellisAspOptions
Inheritance
TrellisAspOptions
Inherited Members
Extension Methods

Examples

Zero-config — uses defaults:

builder.Services.AddTrellisAsp();

Override specific mappings:

builder.Services.AddTrellisAsp(options =>
{
    options.MapError<DomainError>(StatusCodes.Status400BadRequest);
});

Remarks

By default, all standard error types are mapped to conventional HTTP status codes:

Error TypeDefault HTTP Status
Error.UnprocessableContent422 Unprocessable Entity
Error.BadRequest400 Bad Request
Error.Unauthorized401 Unauthorized
Error.Forbidden403 Forbidden
Error.NotFound404 Not Found
Error.Conflict409 Conflict
Error.PreconditionFailed412 Precondition Failed
Error.PreconditionRequired428 Precondition Required
Error.TooManyRequests429 Too Many Requests
Error.InternalServerError500 Internal Server Error
Error.Unexpected500 Internal Server Error
Error.ServiceUnavailable503 Service Unavailable

Use MapError<TError>(int) to override any mapping. Unmapped error types fall back to 500 Internal Server Error.

Methods

MapError<TError>(int)

Maps an error type to an HTTP status code. Overrides the default mapping if one exists.

public TrellisAspOptions MapError<TError>(int statusCode) where TError : Error

Parameters

statusCode int

The HTTP status code to return for this error type.

Returns

TrellisAspOptions

The options instance for fluent chaining.

Type Parameters

TError

The error type to map. Must derive from Error.

Examples

options.MapError<Error.Conflict>(StatusCodes.Status400BadRequest)
       .MapError<Error.UnprocessableContent>(StatusCodes.Status422UnprocessableEntity);