using Groceries.Common; using Groceries.Data; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.EntityFrameworkCore; var builder = WebApplication.CreateBuilder(args); var env = builder.Environment; var dataDir = builder.Configuration.GetValue("data") ?? env.ContentRootPath; builder.Configuration .AddIniFile(Path.Combine(dataDir, "config.ini"), optional: true, reloadOnChange: true) .AddIniFile(Path.Combine(dataDir, $"config_{env.EnvironmentName}.ini"), optional: true, reloadOnChange: true); var dataProtection = builder.Services.AddDataProtection(); if (env.IsProduction()) { dataProtection.PersistKeysToFileSystem(new DirectoryInfo(Path.Combine(dataDir, "keys"))); } var mvc = builder.Services .AddControllersWithViews() .AddRazorOptions(options => { options.ViewLocationFormats.Clear(); options.ViewLocationFormats.Add("/{1}/{0}" + RazorViewEngine.ViewExtension); options.ViewLocationFormats.Add("/Common/{0}" + RazorViewEngine.ViewExtension); }) .AddSessionStateTempDataProvider(); if (env.IsDevelopment()) { mvc.AddRazorRuntimeCompilation(); } builder.Services.AddDistributedMemoryCache(); builder.Services.AddSession(); builder.Services.AddSingleton, TurboStreamResultExecutor>(); builder.Services.AddDbContextPool(options => options .EnableDetailedErrors(env.IsDevelopment()) .EnableSensitiveDataLogging(env.IsDevelopment()) .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking) .UseSnakeCaseNamingConvention() .UseNpgsql(builder.Configuration["Database"]!)); var app = builder.Build(); app.UseStaticFiles(); app.UseRouting(); app.UseSession(); app.MapControllers(); app.Run();