Replace Cultures with MultiCulture and update middleware order

Switched configuration and DI from Cultures to MultiCulture.
Adjusted middleware registration so CultureMiddleware runs after ExceptionHandlingMiddleware.
This commit is contained in:
2026-02-12 17:16:47 +01:00
parent 0e270e3182
commit 297ab458c7

View File

@@ -165,8 +165,8 @@ try
});
// Register the FlagIconCssClass instance as a singleton
builder.Services.Configure<Cultures>(config.GetSection("Cultures"));
builder.Services.AddSingleton(sp => sp.GetRequiredService<IOptions<Cultures>>().Value);
builder.Services.Configure<MultiCulture>(config.GetSection("Cultures"));
builder.Services.AddSingleton(sp => sp.GetRequiredService<IOptions<MultiCulture>>().Value);
// Register mail services
#pragma warning disable CS0618 // Type or member is obsolete
@@ -187,8 +187,8 @@ try
var app = builder.Build();
app.UseMiddleware<CultureMiddleware>();
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.UseMiddleware<CultureMiddleware>();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
@@ -230,7 +230,7 @@ try
app.UseAuthentication();
app.UseAuthorization();
var cultures = app.Services.GetRequiredService<Cultures>();
var cultures = app.Services.GetRequiredService<MultiCulture>();
if (!cultures.Any())
throw new InvalidOperationException(@"Languages section is missing in the appsettings. Please configure like following.
Language is both a name of the culture and the name of the resx file such as Resource.de-DE.resx