using HyperBooru.ApiClient; using HyperBooru.Server.Components; using HyperBooru.Services; using Microsoft.AspNetCore.DataProtection; using Microsoft.EntityFrameworkCore; using System.Text.Json.Serialization; namespace HyperBooru.Server; public class Program { public static void Main(string[] args) { var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddHttpContextAccessor(); builder.Services.AddControllers().AddJsonOptions(o => { var converter = new JsonStringEnumConverter(); o.JsonSerializerOptions.Converters.Add(converter); }); builder.Services.AddRazorComponents() .AddInteractiveWebAssemblyComponents(); // Add our custom services builder.Services.AddSingleton(); builder.Services.AddDbContextFactory(); builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddHostedService(); builder.Services.AddSingleton(); builder.Services.AddSingleton(sp => new HBSession() { BaseUri = new("https://127.0.0.1:7084") }); // Ensure session keys are stored in a persistent location on all platforms builder.Services.AddDataProtection() .PersistKeysToFileSystem(new( builder.Services.BuildServiceProvider() .GetRequiredService() .KeyPath)); var app = builder.Build(); // Ensure database is created and it's schema is up to date using var scope = app.Services.CreateScope(); using var db = scope.ServiceProvider.GetRequiredService(); db.Database.Migrate(); // Configure the HTTP request pipeline. if(app.Environment.IsDevelopment()) { app.UseWebAssemblyDebugging(); } else { app.UseExceptionHandler("/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true); app.UseHttpsRedirection(); app.UseAntiforgery(); app.MapStaticAssets(); app.MapControllers(); app.MapRazorComponents() .AddInteractiveWebAssemblyRenderMode() .AddAdditionalAssemblies(typeof(Client._Imports).Assembly); app.Run(); } }