Shared : Presentation Minimal API

The Shared.Presentation.MinimalApi project provides the presentation layer abstractions and utilities for ASP.NET Core Minimal API applications. It includes an endpoint interface, dependency injection helpers for service and endpoint registration, CORS configuration, global exception handling, and a Result-to-ProblemDetails conversion extension.

Abstractions : Endpoints

The IEndpoint interface defines a single AddRoutes method that endpoints implement to register their routes on the IEndpointRouteBuilder. This provides a modular pattern for organizing Minimal API endpoints.

Dependency Injection

The dependency injection extensions provide configuration helpers for Minimal API services, endpoint registration, and middleware pipeline setup :
  • WebApplicationBuilderExtension : Provides AddMinimalApi to register CORS (with validated allowed origins), problem details, a global exception handler, and OpenAPI with an Accept-Language header parameter on all operations. Also provides RegisterEndpoints and AddEndpoints to discover and register all IEndpoint implementations from a given assembly.
  • WebApplicationExtension : Provides UseExceptionHandling to enable the global exception handler middleware, UseMinimalApi to configure CORS, OpenAPI and Scalar API reference (in development), HSTS, and HTTPS redirection, and UseEndpoints to resolve all registered IEndpoint services and map their routes.

Extensions : Results

The ToProblemDetailsExtension class provides an extension method that converts a read-only list of Error objects into an IResult containing a ProblemDetailsDto. It maps the first non-internal error type to the appropriate HTTP status code, title, and RFC link (400 Bad Request, 404 Not Found, 422 Unprocessable Entity, or 500 Internal Server Error), and returns the response as application/problem+json.

Handlers : Error Manager

The ErrorManagerHandler is a sealed IExceptionHandler implementation that provides global exception handling for the Minimal API. It logs OperationCanceledException as warnings and returns a 499 status code, while all other exceptions are logged as errors and returned as a ProblemDetailsDto JSON response with a 500 status code. In debug mode, the full exception details are included; in release mode, a generic "Unknown error" message is returned.

Options : CORS

The CORS options define the cross-origin resource sharing configuration for the Minimal API :
  • CorsOption : A sealed options class that holds the array of allowed origins, bound from the Cors configuration section. It also defines the section name and the CORS policy name as constants.
  • CorsOptionValidator : A FluentValidation validator that ensures the AllowedOrigins array is not empty.

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.