diff --git a/src/NexusReader.Web.Client/Program.cs b/src/NexusReader.Web.Client/Program.cs index 736517f..502d247 100644 --- a/src/NexusReader.Web.Client/Program.cs +++ b/src/NexusReader.Web.Client/Program.cs @@ -1,65 +1,52 @@ +using Microsoft.AspNetCore.Components.Web; using Microsoft.AspNetCore.Components.WebAssembly.Hosting; -using Microsoft.AspNetCore.Components.Authorization; +using NexusReader.Web.Client; +using NexusReader.UI.Shared.Services; using NexusReader.Application.Abstractions.Services; using NexusReader.Web.Client.Services; -using NexusReader.UI.Shared.Services; +using Microsoft.AspNetCore.Components.Authorization; +using NexusReader.Web.Client.Handlers; using NexusReader.Application; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.AI; -using NexusReader.Data.Persistence; - var builder = WebAssemblyHostBuilder.CreateDefault(args); -// Platform & UI Services -builder.Services.AddScoped(); +// --- Identity & Auth --- +builder.Services.AddAuthorizationCore(); +builder.Services.AddScoped(); + +// --- Storage & Platform --- builder.Services.AddScoped(); +builder.Services.AddScoped(); + +// --- Identity Service (WASM) --- +builder.Services.AddScoped(); + +// --- App Services --- +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); -builder.Services.AddScoped(); +builder.Services.AddScoped(); builder.Services.AddScoped(); +builder.Services.AddScoped(); -// Identity & Auth Services -builder.Services.AddOptions(); -builder.Services.AddAuthorizationCore(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(sp => sp.GetRequiredService()); -builder.Services.AddCascadingAuthenticationState(); +// --- Application Layer (Mappings etc) --- +builder.Services.AddApplication(); -// AI & Content Services -builder.Services.AddScoped(); +// --- HttpClient Configuration --- +builder.Services.AddTransient(); -builder.Services.AddTransient(); builder.Services.AddHttpClient("NexusAPI", client => -{ - client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress); -}).AddHttpMessageHandler(); + { + client.BaseAddress = new Uri(builder.HostEnvironment.BaseAddress); + }) + .AddHttpMessageHandler(); +// Default HttpClient for services that don't need the header handler (or handle it themselves) builder.Services.AddScoped(sp => sp.GetRequiredService().CreateClient("NexusAPI")); -// Dummy registrations for server-only handlers to satisfy DI validation -builder.Services.AddSingleton>(new ThrowingDbContextFactory()); -builder.Services.AddSingleton>>(new ThrowingEmbeddingGenerator()); - -builder.Services.AddApplication(); -builder.Services.AddScoped(); - await builder.Build().RunAsync(); - -public class ThrowingDbContextFactory : IDbContextFactory -{ - public AppDbContext CreateDbContext() => throw new NotSupportedException("DbContext cannot be used in WASM client."); -} - -public class ThrowingEmbeddingGenerator : IEmbeddingGenerator> -{ - public void Dispose() { } - public Task>> GenerateAsync(IEnumerable values, EmbeddingGenerationOptions? options = null, CancellationToken cancellationToken = default) - => throw new NotSupportedException("Embedding generation cannot be used in WASM client."); - public object? GetService(Type serviceType, object? serviceKey = null) => null; -}