111 lines
3.5 KiB
C#
111 lines
3.5 KiB
C#
using Blazored.LocalStorage;
|
|
using Blazored.SessionStorage;
|
|
using GPW.CORE.Data;
|
|
using GPW.CORE.Services;
|
|
using GPW.CORE.Smart8.Components;
|
|
using GPW.CORE.Smart8.Data;
|
|
using Microsoft.AspNetCore.Identity.UI.Services;
|
|
using Microsoft.AspNetCore.Localization;
|
|
using NLog;
|
|
using NLog.Web;
|
|
using StackExchange.Redis;
|
|
using System.Globalization;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var env = builder.Environment;
|
|
|
|
var logger = LogManager.Setup()
|
|
.LoadConfigurationFromAppSettings()
|
|
.GetCurrentClassLogger();
|
|
|
|
ConfigurationManager configuration = builder.Configuration;
|
|
logger.Info("GPW.Smart | Program.cs: startup");
|
|
logger.Info($"Current ASPNETCORE_ENVIRONMENT: {env.EnvironmentName}");
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorComponents()
|
|
.AddInteractiveServerComponents()
|
|
.AddInteractiveWebAssemblyComponents();
|
|
|
|
|
|
// REDIS setup
|
|
string connStringRedis = configuration.GetConnectionString("Redis")!;
|
|
string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":"));
|
|
// avvio oggetto shared x redis...
|
|
var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis);
|
|
|
|
// abilitazione x email management con MailKit
|
|
builder.Services.AddTransient<IEmailSender, MailKitEmailSender>();
|
|
|
|
builder.Services.Configure<MailKitEmailSenderOptions>(options =>
|
|
{
|
|
options.Host_Address = configuration["ExternalProviders:MailKit:SMTP:Address"]!;
|
|
options.Host_Port = Convert.ToInt32(configuration["ExternalProviders:MailKit:SMTP:Port"]);
|
|
options.Host_Username = configuration["ExternalProviders:MailKit:SMTP:Account"]!;
|
|
options.Host_Password = configuration["ExternalProviders:MailKit:SMTP:Password"]!;
|
|
options.Sender_EMail = configuration["ExternalProviders:MailKit:SMTP:SenderEmail"]!;
|
|
options.Sender_Name = configuration["ExternalProviders:MailKit:SMTP:SenderName"]!;
|
|
});
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddRazorPages();
|
|
builder.Services.AddServerSideBlazor();
|
|
builder.Services.AddSingleton<CoreSmartDataService>();
|
|
builder.Services.AddSingleton<LicenseServiceLoc>();
|
|
builder.Services.AddSingleton<IConnectionMultiplexer>(redisMultiplexer);
|
|
builder.Services.AddScoped<MessageServiceLoc>();
|
|
builder.Services.AddScoped<UserStateService>();
|
|
builder.Services.AddScoped<UIMessageService>();
|
|
|
|
|
|
builder.Services.AddHttpContextAccessor();
|
|
|
|
builder.Services.AddBlazoredLocalStorage();
|
|
builder.Services.AddBlazoredSessionStorage();
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
// aggiunt base URL x routing corretto
|
|
app.UsePathBase(configuration.GetValue<string>("OptConf:BaseUrl"));
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseWebAssemblyDebugging();
|
|
}
|
|
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(GPW.CORE.Smart8.Client._Imports).Assembly);
|
|
|
|
app.Run();
|