Skip to content

Pact Localization DynamicLocalizationMiddleware

welshronaldo edited this page May 30, 2022 · 6 revisions

DynamicLocalizationMiddleware Class

Enables automatic setting of the culture for Microsoft.AspNetCore.Http.HttpRequests based on information
sent by the client in headers and logic provided by the application.

public class DynamicLocalizationMiddleware

Inheritance System.Object 🡒 DynamicLocalizationMiddleware

Constructors
DynamicLocalizationMiddleware(RequestDelegate, IOptions<RequestLocalizationOptions>) This implementation is derived from the built-in Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.
Rather than adopting a static "Supported Cultures" list from the options, we'll instead be picking up the available cultures based on the request
You'll need to inject a service based on the ISupportedCulturesResolver interface that will be provide that logic
NOTE: probably want this placed towards the bottom of the middleware stack to ensure the HttpContext is furnished with an Identity by the time it arrives
Methods
InvokeAsync(HttpContext) Invokes the logic of the middleware.
Clone this wiki locally