Inject framework HttpClient to support prerendering behavior on server instead of baking in the HttpClient on the client project

This commit is contained in:
daniel-c-harvey
2025-09-04 09:48:58 -04:00
parent 9124e82e24
commit d556d32829
9 changed files with 59 additions and 33 deletions
+6 -4
View File
@@ -1,18 +1,20 @@
using DeepDrftWeb;
using MudBlazor.Services;
using DeepDrftWeb.Components;
using DeepDrftWeb.Data;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add MudBlazor services
builder.Services.AddMudServices();
// Add HttpClient services for prerendering
builder.Services.AddHttpClient("DeepDrft.API", client => client.BaseAddress = new Uri(Startup.GetKestrelUrl(builder)));
builder.Services.AddScoped(sp =>
sp.GetRequiredService<IHttpClientFactory>().CreateClient("DeepDrft.API"));
Startup.ConfigureDomainServices(builder);
var hostUrl = builder.Configuration.GetValue<string>("ASPNETCORE_URLS")?.Split(';').First() ?? throw new Exception("ASPNETCORE_URLS undefined");
DeepDrftWeb.Client.Startup.ConfigureDomainServices(builder.Services, hostUrl);
DeepDrftWeb.Client.Startup.ConfigureDomainServices(builder.Services);
builder.Services.AddControllers();