Table of Contents

Class WebApplicationExtensions

Namespace
arolariu.Backend.Core.Domain.General.Extensions
Assembly
arolariu.Backend.Core.dll

Provides extension methods for configuring the WebApplication request processing pipeline. This class contains middleware configuration and request routing setup for the general domain.

[ExcludeFromCodeCoverage]
internal static class WebApplicationExtensions
Inheritance
WebApplicationExtensions
Inherited Members

Remarks

This class complements WebApplicationBuilderExtensions by configuring the request pipeline after services have been registered. It sets up middleware in the correct order to ensure proper request processing and response handling.

The middleware pipeline is configured in a specific order that follows ASP.NET Core best practices: - Security middleware (HTTPS redirection) - Static files serving - Localization and CORS - API documentation (Swagger) - Health checks and monitoring - Authentication and authorization

Methods

AddGeneralApplicationConfiguration(WebApplication)

Configures the WebApplication request pipeline with general domain middleware and routing. This method establishes the complete request processing pipeline for cross-cutting concerns.

internal static WebApplication AddGeneralApplicationConfiguration(this WebApplication app)

Parameters

app WebApplication

The WebApplication instance to configure with the request pipeline.

Returns

WebApplication

The same WebApplication instance for method chaining.

Examples

// Usage in Program.cs after building the WebApplication
WebApplication app = builder.Build();
app.AddGeneralApplicationConfiguration();

// Continue with domain-specific pipeline configuration
app.AddInvoiceDomainConfiguration();

app.Run();

Remarks

This method configures the middleware pipeline in the following order:

1. Static Files: Serves static content (CSS, JS, images) before other middleware to optimize performance and reduce unnecessary processing.

2. HTTPS Redirection: Automatically redirects HTTP requests to HTTPS for security, ensuring all communication is encrypted in production environments.

3. Request Localization: Enables multi-language support by detecting and setting the appropriate culture based on request headers, query parameters, or cookies.

4. CORS (Cross-Origin Resource Sharing): Applies the "AllowAllOrigins" policy to enable cross-origin requests from web applications hosted on different domains. Note: This permissive policy should be restricted in production environments.

5. Swagger Documentation: Configures OpenAPI/Swagger endpoints for API documentation and interactive testing interface, enhancing developer experience and API discoverability.

6. Health Checks: Exposes the "/health" endpoint with detailed health information formatted for consumption by monitoring tools and health check dashboards.

7. Terms and Conditions Endpoint: Maps a simple GET endpoint to retrieve terms and conditions from configuration, supporting legal compliance requirements.

8. Authentication Services: Integrates authentication middleware and policies through the Auth module, enabling secure access to protected resources.

Exceptions

ArgumentNullException

Thrown when the app parameter is null.

See Also