104 lines
3.3 KiB
C#
104 lines
3.3 KiB
C#
using EgwCoreLib.Lux.Data.Services;
|
|
using Lux.UI.Client.Pages;
|
|
using Lux.UI.Components;
|
|
using Lux.UI.Components.Account;
|
|
using Lux.UI.Data;
|
|
using Microsoft.AspNetCore.Components.Authorization;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using NLog;
|
|
using NLog.Web;
|
|
using System.Globalization;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
var logger = LogManager.Setup()
|
|
.LoadConfigurationFromAppSettings()
|
|
.GetCurrentClassLogger();
|
|
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
logger.Info("Program.cs: startup");
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents()
|
|
.AddInteractiveWebAssemblyComponents();
|
|
|
|
builder.Services.AddCascadingAuthenticationState();
|
|
builder.Services.AddScoped<IdentityUserAccessor>();
|
|
builder.Services.AddScoped<IdentityRedirectManager>();
|
|
builder.Services.AddScoped<AuthenticationStateProvider, PersistingRevalidatingAuthenticationStateProvider>();
|
|
|
|
builder.Services.AddAuthentication(options =>
|
|
{
|
|
options.DefaultScheme = IdentityConstants.ApplicationScheme;
|
|
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
|
|
})
|
|
.AddIdentityCookies();
|
|
|
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection") ?? throw new InvalidOperationException("Connection string 'DefaultConnection' not found.");
|
|
builder.Services.AddDbContext<ApplicationDbContext>(options =>
|
|
options.UseSqlServer(connectionString));
|
|
builder.Services.AddDatabaseDeveloperPageExceptionFilter();
|
|
|
|
builder.Services.AddIdentityCore<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
|
|
.AddEntityFrameworkStores<ApplicationDbContext>()
|
|
.AddSignInManager()
|
|
.AddDefaultTokenProviders();
|
|
|
|
builder.Services.AddSingleton<IEmailSender<ApplicationUser>, IdentityNoOpEmailSender>();
|
|
|
|
// Aggiunta servizi specifici
|
|
builder.Services.AddSingleton<DataLayerServices>();
|
|
|
|
var app = builder.Build();
|
|
|
|
// aggiunt base URL x routing corretto
|
|
string baseUrl = configuration.GetValue<string>("ServerConf:BaseUrl") ?? "";
|
|
app.UsePathBase(baseUrl);
|
|
logger.Info($"BaseUrl: {baseUrl}");
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseWebAssemblyDebugging();
|
|
app.UseMigrationsEndPoint();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error", createScopeForErrors: true);
|
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
|
app.UseHsts();
|
|
}
|
|
|
|
|
|
// cultura IT...
|
|
var supportedCultures = new[]{
|
|
new CultureInfo("it-IT")
|
|
};
|
|
app.UseRequestLocalization(new RequestLocalizationOptions
|
|
{
|
|
DefaultRequestCulture = new RequestCulture("it-IT"),
|
|
SupportedCultures = supportedCultures,
|
|
FallBackToParentCultures = false
|
|
});
|
|
CultureInfo.DefaultThreadCurrentCulture = CultureInfo.CreateSpecificCulture("it-IT");
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseStaticFiles();
|
|
app.UseAntiforgery();
|
|
|
|
app.MapRazorComponents<App>()
|
|
.AddInteractiveServerRenderMode()
|
|
.AddInteractiveWebAssemblyRenderMode()
|
|
.AddAdditionalAssemblies(typeof(Lux.UI.Client._Imports).Assembly);
|
|
|
|
// Add additional endpoints required by the Identity /Account Razor components.
|
|
app.MapAdditionalIdentityEndpoints();
|
|
|
|
app.Run();
|