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