Extensions
The primary goal of this namespace is to enhance the developer experience by providing convenient "shortcut" and "setup" methods. These extension methods reduce boilerplate code and simplify common API development tasks in ASP.NET Core. They abstract away setup complexity and provide elegant shortcuts, guiding developers toward writing cleaner, more organized, and more maintainable API code.
The namespace contains several key classes, each serving a distinct purpose:
1. HttpEndpointServiceCollectionExtensions
This class is the engine behind your Endpoint Registration feature.
Its purpose is to declutter your Program.cs file by discovering and mapping API endpoints at compile time through the source generator shipped with the package.
This is a core pattern for implementing a clean Vertical Slice Architecture.
2. ValidationExtensions
This class is designed to improve the developer experience when applying validation to Minimal API endpoints.
It provides a more fluent and readable syntax for adding the ValidationEndpointFilter.
3. ApplicationBuilderExtensions
This class provides the Use (pipeline registration) method for every middleware shipped with the package:
UseRaExceptionHandling()— adds theGlobalExceptionHandlermiddleware to the pipeline, ensuring every unhandled exception is logged and returned to the client as a structured error response.UseDefaultHeadersMiddleware()— adds theDefaultHeadersMiddlewareto the pipeline, enforcing the required headers configured inDefaultHeadersOptions.RequiredHeaders.UseLoggingMiddleware()— adds theLoggingMiddlewarefor structured HTTP request/response logging.UseContextLoggingMiddleware()— adds theContextLoggingMiddleware, which enriches log entries with request-scoped context such as the correlation ID. (The middleware type was renamed fromRequestContextLoggingMiddlewarein v10.2.1, and itsUsemethod with it —AddRequestContextLoggingMiddleware()is unchanged.)
4. ServiceCollectionExtensions
This class provides the matching Add (service registration) methods — each Use method above must be preceded by its counterpart here:
AddRaExceptionHandling()— registers theGlobalExceptionHandlerwith the dependency injection container.AddDefaultHeadersMiddleware()— registers theDefaultHeadersMiddlewareand configuresDefaultHeadersOptions.AddLoggingMiddleware()— registers theLoggingMiddlewareand configuresHttpLoggingOptions.AddRequestContextLoggingMiddleware()— registers theContextLoggingMiddlewarewith the dependency injection container.
The former MiddlewareExtensions class was split into ApplicationBuilderExtensions (Use methods) and ServiceCollectionExtensions (Add methods). All extension methods keep their names — only code that references the class name directly needs updating. See the migration guide for details.
ApplicationBuilderExtensions
The ApplicationBuilderExtensions class provides the Use extension methods that register every middleware shipped with this package in the request pipeline: the DefaultHeadersMiddleware, the GlobalExceptionHandler, the LoggingMiddleware, and the ContextLoggingMiddleware.
ServiceCollectionExtensions
The ServiceCollectionExtensions class provides the Add extension methods that register every middleware shipped with this package — and its options — in the dependency injection container: the DefaultHeadersMiddleware, the GlobalExceptionHandler, the LoggingMiddleware, and the ContextLoggingMiddleware.
HttpEndpointServiceCollectionExtensions
The HttpEndpointServiceCollectionExtensions class is the engine behind your Endpoint Registration feature.
ValidationExtensions
The ValidationExtensions class is designed to improve the developer experience when applying validation to Minimal API endpoints. It provides a more fluent and readable syntax for adding the ValidationEndpointFilter.