summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Mannens <jake@asger.xyz>2026-05-24 02:01:20 +1000
committerJake Mannens <jake@asger.xyz>2026-06-11 01:13:31 +1000
commita4d211544bbb3a51d1543bc7d1954e35a48f0adc (patch)
tree5e75d781042b57bda87354d6e00526ec92ee7e39
parent8ece5680f95487e60e11657c29a8ca2247072f84 (diff)
Converted Program.cs to WASM
-rw-r--r--Program.cs71
1 files 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<JsonOptions>(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<IConfigService, ConfigService>();
- builder.Services.AddDbContextFactory<HBContext>();
- builder.Services.AddScoped<IFeedService, FeedService>();
- builder.Services.AddScoped<ITagService, TagService>();
- builder.Services.AddScoped<IMediaService, MediaService>();
- builder.Services.AddSingleton<IGlobalUserService, GlobalUserService>();
- builder.Services.AddScoped<IUserService, UserService>();
- builder.Services.AddHostedService<OcrService>();
builder.Services.AddSingleton<ISourceService, SourceService>();
+ builder.Services.AddSingleton<HBSession>(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<IConfigService>()
- .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<HBContext>();
- db.Database.Migrate();
-
- app.UseRouting();
- app.UseSession();
- app.UseAuthentication();
- app.UseAuthorization();
- app.UseHsts();
- app.UseHttpsRedirection();
- app.UseStaticFiles();
- app.UseMiddleware<ExceptionMiddleware>();
- app.MapBlazorHub();
- app.MapControllers();
- app.MapFallbackToPage("/_Host");
-
- app.Run();
+ await builder.Build().RunAsync();
}
}