using AuthorBuddy.Web.Components; using AuthorBuddy.Web.Models; using AuthorBuddy.Web.Services; using LiteDB; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Components.Authorization; var builder = WebApplication.CreateBuilder(args); builder.Services.AddRazorComponents() .AddInteractiveServerComponents(); var dbPath = Path.Combine(AppContext.BaseDirectory, Constants.DbFile); builder.Services.AddSingleton(new LiteDatabase($"Filename={dbPath};Connection=direct")); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(sp => sp.GetRequiredService()); builder.Services.AddAuthorizationCore(); builder.Services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(options => { options.LoginPath = "/login"; options.Cookie.HttpOnly = true; options.ExpireTimeSpan = TimeSpan.FromDays(30); }); var app = builder.Build(); var settingsInit = app.Services.GetRequiredService(); settingsInit.InitializeAsync().GetAwaiter().GetResult(); if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/Error", createScopeForErrors: true); } app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); app.Run(); public partial class Program { public const bool DebugAutoLogin = true; }