From a4d211544bbb3a51d1543bc7d1954e35a48f0adc Mon Sep 17 00:00:00 2001 From: Jake Mannens Date: Sun, 24 May 2026 02:01:20 +1000 Subject: Converted Program.cs to WASM --- Program.cs | 71 ++++++++++---------------------------------------------------- 1 file changed, 11 insertions(+), 60 deletions(-) diff --git a/Program.cs b/Program.cs index 5863368..243f3cd 100644 --- a/Program.cs +++ b/Program.cs @@ -1,67 +1,18 @@ -using HyperBooru.Services; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.DataProtection; -using Microsoft.AspNetCore.Http.Json; -using Microsoft.EntityFrameworkCore; -using System.Text.Json.Serialization; +using HyperBooru.ApiClient; +using HyperBooru.Client.Services; +using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -namespace HyperBooru; +namespace HyperBooru.Client; -public class Program { - public static void Main(string[] args) { - var builder = WebApplication.CreateBuilder(args); - builder.Services.AddSession(); - builder.Services.AddHttpContextAccessor(); - builder.Services.AddAuthentication( - CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(); - builder.Services.AddAuthorization(); - builder.Services.AddControllers().AddJsonOptions(o => { - var converter = new JsonStringEnumConverter(); - o.JsonSerializerOptions.Converters.Add(converter); - }); - builder.Services.Configure(o => { - o.SerializerOptions.TypeInfoResolverChain.Insert(0, new ExceptionJsonResolver()); - }); - builder.Services.AddRazorPages(); - builder.Services.AddServerSideBlazor(); +internal class Program { + static async Task Main(string[] args) { + var builder = WebAssemblyHostBuilder.CreateDefault(args); - // Add our custom services - builder.Services.AddSingleton(); - builder.Services.AddDbContextFactory(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); - builder.Services.AddScoped(); - builder.Services.AddSingleton(); - builder.Services.AddScoped(); - builder.Services.AddHostedService(); builder.Services.AddSingleton(); + builder.Services.AddSingleton(sp => new(new HttpClient { + BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) + })); - // 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(); - - app.UseRouting(); - app.UseSession(); - app.UseAuthentication(); - app.UseAuthorization(); - app.UseHsts(); - app.UseHttpsRedirection(); - app.UseStaticFiles(); - app.UseMiddleware(); - app.MapBlazorHub(); - app.MapControllers(); - app.MapFallbackToPage("/_Host"); - - app.Run(); + await builder.Build().RunAsync(); } } -- cgit v1.3