Register DI services for SSR and update API base URL
Added server-side DI registrations for authentication and app-specific services to support Blazor InteractiveAuto prerendering. Registered a scoped HttpClient with base URI for correct API routing. Switched ApiBaseUrl in appsettings.json to https://localhost:8088. Added necessary using statements for new services and providers.
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
using EnvelopeGenerator.ReceiverUI.Components;
|
||||
using EnvelopeGenerator.ReceiverUI.Client.Auth;
|
||||
using EnvelopeGenerator.ReceiverUI.Client.Services;
|
||||
using EnvelopeGenerator.ReceiverUI.Client.State;
|
||||
using EnvelopeGenerator.ReceiverUI.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
@@ -14,6 +18,32 @@ var apiBaseUrl = builder.Configuration["ApiBaseUrl"]
|
||||
|
||||
builder.Services.AddHttpForwarder();
|
||||
|
||||
// ── Services: Müssen AUCH auf dem Server registriert sein ──
|
||||
// WARUM? Bei @rendermode InteractiveAuto rendert Blazor die Seite zuerst
|
||||
// auf dem Server (SSR/Prerendering). Dabei resolved es @inject-Properties.
|
||||
// Wenn ein Service nur im Client-Projekt (WASM) registriert ist, aber nicht
|
||||
// hier, gibt es eine InvalidOperationException beim Prerendering.
|
||||
//
|
||||
// Der HttpClient auf dem Server zeigt auf sich selbst (localhost),
|
||||
// weil die /api/* Requests über MapForwarder an die echte API gehen.
|
||||
builder.Services.AddScoped(sp =>
|
||||
{
|
||||
var navigationManager = sp.GetService<Microsoft.AspNetCore.Components.NavigationManager>();
|
||||
var baseUri = navigationManager?.BaseUri ?? $"https://localhost:{builder.Configuration["ASPNETCORE_HTTPS_PORT"] ?? "7206"}/";
|
||||
return new HttpClient { BaseAddress = new Uri(baseUri) };
|
||||
});
|
||||
|
||||
builder.Services.AddAuthorizationCore();
|
||||
builder.Services.AddScoped<ApiAuthStateProvider>();
|
||||
builder.Services.AddScoped<AuthenticationStateProvider>(sp =>
|
||||
sp.GetRequiredService<ApiAuthStateProvider>());
|
||||
|
||||
builder.Services.AddScoped<IAuthService, AuthService>();
|
||||
builder.Services.AddScoped<IEnvelopeService, EnvelopeService>();
|
||||
builder.Services.AddScoped<IReceiverAuthService, ReceiverAuthService>();
|
||||
builder.Services.AddScoped<EnvelopeState>();
|
||||
builder.Services.AddScoped<ToastService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
if (app.Environment.IsDevelopment())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"ApiBaseUrl": "https://localhost:5001",
|
||||
"ApiBaseUrl": "https://localhost:8088",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
|
||||
Reference in New Issue
Block a user