forked from iso8859/AspNetCoreAuthMultiLang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
64 lines (52 loc) · 2.03 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using AspNetCoreAuthMultiLang.Data;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Options;
using System.Globalization;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddSingleton<WeatherForecastService>();
// For authentication
builder.Services.AddAuthorizationCore();
// Here create an instance of the DB layer you want to use
builder.Services.AddSingleton<AspNetCoreAuthMultiLang.IDBAbstraction>(new AspNetCoreAuthMultiLang.DBMemory());
// Here we specify our version of AuthenticationStateProvider
builder.Services.AddScoped<AuthenticationStateProvider, AspNetCoreAuthMultiLang.MyServerAuthenticationStateProvider>();
builder.Services.AddHttpContextAccessor();
#region Localization
builder.Services.AddLocalization(option => option.ResourcesPath = "Resources");
builder.Services.Configure<RequestLocalizationOptions>(options =>
{
var supportedCultures = new List<CultureInfo>()
{
new CultureInfo("en-US"),
new CultureInfo("fr-FR")
};
options.DefaultRequestCulture = new RequestCulture("en-US");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
#endregion
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
#region Localisation
app.UseRequestLocalization(app.Services.GetService<IOptions<RequestLocalizationOptions>>().Value);
#endregion
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
// For authentication
app.UseAuthentication();
app.UseAuthorization();
app.MapBlazorHub();
app.MapControllers();
app.MapFallbackToPage("/_Host");
app.Run();