Shared : Presentation Blazor WebAssembly
The Shared.Presentation.BlazorWebAssembly project provides configuration extensions and utilities specific to Blazor WebAssembly applications. It includes helpers for Serilog logging, localization, HttpClient registration with culture propagation, root component mapping, and Web API options with validation.
Dependency Injection
The dependency injection extensions provide configuration helpers for the WebAssembly host builder and host :
- WebAssemblyHostBuilderExtension : Provides
AddSerilogto configure Serilog with a bootstrap console logger,AddLocalizationto register localization services and validate theLocalizationOption,AddHttpClientto register a named HttpClient with the Web API base address and a culture message handler, andAddBlazorWebAssembly<TRoutes>to register root components (HeadOutlet and the Routes component). - WebAssemblyHostExtension : Provides
UseLocalStorageCultureAsyncto read the saved culture from browser local storage via JS interop and apply it to the current thread culture, andUseFluentValidationDisplayNameResolverto set a global FluentValidation display name resolver that resolves property names from application and domain resource files with fallback.
Handlers
The CultureHttpMessageHandler is a sealed DelegatingHandler that automatically injects the current culture into the Accept-Language header of every outgoing HTTP request, ensuring the Web API receives the correct culture for localized responses.
Options : Web API
The Web API options define the configuration for the HttpClient used to communicate with the backend API :
- WebApiOption : A sealed options class that holds the Web API base address, bound from the
WebApiconfiguration section. It also defines the section name and the HttpClient name as constants. - WebApiOptionValidator : A FluentValidation validator that ensures the
BaseAddressproperty is not empty.