arolariu.Backend.Core.Domain.General.Extensions
arolariu.Backend.Core
arolariu.Backend.Core.Domain.General.Extensions Namespace
Classes
CosmosDbHealthCheck Class
Lightweight health check that verifies CosmosDB endpoint reachability. Uses a shared HttpClient to avoid socket exhaustion from repeated checks.
internal sealed class CosmosDbHealthCheck : Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck
Inheritance System.Object 🡒 CosmosDbHealthCheck
Implements Microsoft.Extensions.Diagnostics.HealthChecks.IHealthCheck
Constructors
CosmosDbHealthCheck(string) Constructor
Lightweight health check that verifies CosmosDB endpoint reachability. Uses a shared HttpClient to avoid socket exhaustion from repeated checks.
public CosmosDbHealthCheck(string endpoint);
Parameters
endpoint System.String
WebApplicationBuilderExtensions Class
Provides extension methods for configuring the Microsoft.AspNetCore.Builder.WebApplicationBuilder with general domain services and infrastructure. This class serves as the Composition Root for dependency injection, centralizing the configuration of cross-cutting concerns and foundational services required by the application.
internal static class WebApplicationBuilderExtensions
Inheritance System.Object 🡒 WebApplicationBuilderExtensions
Remarks
This class follows the Composition Root pattern, where all dependency injection configuration is centralized in one location. It configures:
- Configuration sources (centralized config proxy, local files)
- Cross-cutting concerns (CORS, localization, HTTP clients)
- Infrastructure services (health checks, telemetry, authentication)
- Third-party integrations (Swagger documentation, Azure services)
The configuration is environment-aware, automatically adjusting between development and production settings based on the ASPNETCORE_ENVIRONMENT variable.
Fields
WebApplicationBuilderExtensions.ConfigProxyUrlAzure Field
Config proxy URL when running in Azure (AZURE_CLIENT_ID present → managed identity auth).
private const string ConfigProxyUrlAzure = "https://exp.arolariu.ro";
Field Value
WebApplicationBuilderExtensions.ConfigProxyUrlDocker Field
Config proxy URL when running in a local Docker environment (service name resolution via Docker DNS).
private const string ConfigProxyUrlDocker = "http://exp";
Field Value
WebApplicationBuilderExtensions.ExpScope Field
Entra ID scope for the exp service bearer-token flow.
private const string ExpScope = "api://950ac239-5c2c-4759-bd83-911e68f6a8c9/.default";
Field Value
Methods
WebApplicationBuilderExtensions.AddGeneralDomainConfiguration(this WebApplicationBuilder) Method
Configures the Microsoft.AspNetCore.Builder.WebApplicationBuilder with general domain services and cross-cutting infrastructure concerns. This method serves as the primary composition root for the application's foundational services.
public static void AddGeneralDomainConfiguration(this Microsoft.AspNetCore.Builder.WebApplicationBuilder builder);
Parameters
builder Microsoft.AspNetCore.Builder.WebApplicationBuilder
The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance to configure with general domain services.
Remarks
This method configures the following service categories in order:
Configuration Sources: - Environment variables for runtime configuration overrides - appsettings.json for base application settings - Environment-specific appsettings files (Development/Production) - Centralized config proxy (exp service) for secure configuration and feature flags
INFRA environment variable:
All three recognised values (azure, proxy, local) route through
AddProxyConfiguration(this WebApplicationBuilder). The actual exp endpoint and authentication strategy are
determined solely by AZURE_CLIENT_ID presence — not by the INFRA value — so local
Docker environments that set INFRA=local transparently reach http://exp.
Configuration values are fetched individually via the config endpoint.
WebApplicationBuilderExtensions.AddLocalConfiguration(this WebApplicationBuilder) Method
Configures the application to use local configuration sources instead of Azure services. Retained as an explicit override for special test or tooling scenarios only.
private static void AddLocalConfiguration(this Microsoft.AspNetCore.Builder.WebApplicationBuilder builder);
Parameters
builder Microsoft.AspNetCore.Builder.WebApplicationBuilder
The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance to configure.
Remarks
This method is not wired into the normal startup switch. All runtime modes
(azure, proxy, local) now route through AddProxyConfiguration(this WebApplicationBuilder) so that even a
local Docker deployment reaches the exp service at http://exp. This method is preserved
only for scenarios where a developer explicitly opts into file-only configuration.
WebApplicationBuilderExtensions.AddProxyConfiguration(this WebApplicationBuilder) Method
Configures the application to fetch configuration values from the exp proxy service using individual key lookups.
private static void AddProxyConfiguration(this Microsoft.AspNetCore.Builder.WebApplicationBuilder builder);
Parameters
builder Microsoft.AspNetCore.Builder.WebApplicationBuilder
The Microsoft.AspNetCore.Builder.WebApplicationBuilder instance to configure.
Remarks
Endpoint selection priority:
EXP_PROXY_URLenv var → explicit override (enables bare-metal dev with Docker infra, e.g.http://localhost:5002).AZURE_CLIENT_IDpresent →https://exp.arolariu.rowith Entra ID bearer token.- Default →
http://exp(Docker service-name DNS) with no auth.
Startup sequence (sync-over-async is safe here — composition root, no SynchronizationContext):
- Fetch each of the 11 config keys individually via
GET /api/v1/config?name={key}. - Seed arolariu.Backend.Common.Configuration.FeatureSnapshotCache (empty — no feature flags for API currently) and arolariu.Backend.Common.Options.AzureOptions.
- Register arolariu.Backend.Common.Configuration.ConfigRefreshHostedService to keep config values current.
WebApplicationExtensions Class
Provides extension methods for configuring the Microsoft.AspNetCore.Builder.WebApplication request processing pipeline. This class contains middleware configuration and request routing setup for the general domain.
internal static class WebApplicationExtensions
Inheritance System.Object 🡒 WebApplicationExtensions
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
WebApplicationExtensions.AddGeneralApplicationConfiguration(this WebApplication) Method
Configures the Microsoft.AspNetCore.Builder.WebApplication request pipeline with general domain middleware and routing. This method establishes the complete request processing pipeline for cross-cutting concerns.
internal static Microsoft.AspNetCore.Builder.WebApplication AddGeneralApplicationConfiguration(this Microsoft.AspNetCore.Builder.WebApplication app);
Parameters
app Microsoft.AspNetCore.Builder.WebApplication
The Microsoft.AspNetCore.Builder.WebApplication instance to configure with the request pipeline.
Returns
Microsoft.AspNetCore.Builder.WebApplication
The same Microsoft.AspNetCore.Builder.WebApplication instance for method chaining.
Exceptions
System.ArgumentNullException
Thrown when the app parameter is null.
Example
// 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.