Refaktorierte HomeController, um standardmäßig das Culture-Cookie zu setzen, falls es fehlt, und die Kultur aus den übergebenen Query-Parametern zu übernehmen.

This commit is contained in:
Developer 02
2024-05-16 10:38:03 +02:00
parent ba723bdddb
commit d7252ce888
18 changed files with 52 additions and 21 deletions

View File

@@ -71,8 +71,7 @@ try
//AddEF Core dbcontext
var connStr = config["Config:ConnectionString"];
builder.Services.AddDbContext<EGDbContext>(options =>
options.UseSqlServer(connStr));
builder.Services.AddDbContext<EGDbContext>(options => options.UseSqlServer(connStr));
//Inject CRUD Service and repositoriesad
builder.Services.AddScoped<IConfigRepository, ConfigRepository>();
@@ -156,7 +155,7 @@ try
builder.Services.AddCookieConsentSettings();
builder.Services.AddCookieBasedLocalizer("Resources");
builder.Services.AddCookieBasedLocalizer();
builder.Services.AddSingleton(HtmlEncoder.Default);
builder.Services.AddSingleton(UrlEncoder.Default);
@@ -207,7 +206,7 @@ try
app.UseAuthorization();
var cultures = app.Services.GetRequiredService<Cultures>();
if(cultures.Any())
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
FIClass is the css class (in wwwroot/lib/flag-icons-main) for the flag of country.