using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Diagnostics; using MP.Data; using MP.Data.Services; using MP.MON.Components; using NLog; using NLog.Web; using StackExchange.Redis; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorComponents() .AddInteractiveServerComponents() .AddInteractiveWebAssemblyComponents(); var logger = LogManager.Setup() .LoadConfigurationFromAppSettings() .GetCurrentClassLogger(); logger.Info("Program.cs: startup"); ConfigurationManager configuration = builder.Configuration; // REDIS setup logger.Info("Setup REDIS"); string connStringRedis = configuration.GetConnectionString("Redis") ?? "localhost:6379"; string redisSrvAddr = connStringRedis.Substring(0, connStringRedis.IndexOf(":")); // avvio oggetto shared x redis... var redisMultiplexer = ConnectionMultiplexer.Connect(connStringRedis); // aggiungo il costruttore x i vari DbContextFactory var connStr = builder.Configuration.GetConnectionString("MP.Mon") ?? throw new InvalidOperationException("ConnString 'MP.Mon' mancante."); builder.Services.AddDbContextFactory(options => options.UseSqlServer(connStr) .EnableSensitiveDataLogging(false) // true solo in Sviluppo .ConfigureWarnings(w => w.Ignore(CoreEventId.ManyServiceProvidersCreatedWarning))); // Add services to the container. logger.Info("Setup Services"); builder.Services.AddSingleton(redisMultiplexer); // Init centralizzato Repository/Servizi da MP.Data Services builder.Services.AddMonDataLayer(); var app = builder.Build(); // 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(); } string basePath = configuration.GetValue("ServerConf:BaseAppPath") ?? "/"; app.UsePathBase(basePath); logger.Info($"Base application path: {basePath}"); app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents() .AddInteractiveServerRenderMode() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(MP.MON.Client._Imports).Assembly); logger.Info("App: Run stage"); app.Run();