79349148

Date: 2025-01-12 00:32:45
Score: 2
Natty:
Report link

I had a similar issue. Support for Blazor WebAssembly projects isn't in Aspire yet. It's because Aspire has no way to pass the service discovery information to the client application except over HTTP.

I made a Nuget package that passes the service discovery information from the AppHost to the client by writing it to the client's appsettings.json files. Hopefully one day the feature will be baked into Aspire.

You use it like this:

Example Program.cs in AppHost

var builder = DistributedApplication.CreateBuilder(args);

var inventoryApi = builder.AddProject<Projects.AspNetCoreWebApi>("inventoryapi");
var billingApi = builder.AddProject<Projects.SomeOtherWebApi>("billingapi");

builder.AddProject<Projects.Blazor>("blazorServer")
    .AddWebAssemblyClient<Projects.Blazor_Client>("blazorWasmClient")
    .WithReference(inventoryApi)
    .WithReference(billingApi);

builder.Build().Run();

Example Program.cs in your Blazor WebAssembly Client Install (on the WebAssembly client) the Microsoft.Extensions.ServiceDiscovery Nuget package to get the official Aspire service discovery functionality that is going to read your resource information from your app settings.

builder.Services.AddServiceDiscovery();
builder.Services.ConfigureHttpClientDefaults(static http =>
{
    http.AddServiceDiscovery();
});

builder.Services.AddHttpClient<IInventoryService, InventoryService>(
    client =>
    {
        client.BaseAddress = new Uri("https+http://inventoryapi");
    });

    builder.Services.AddHttpClient<IBillingService, BillingService>(
    client =>
    {
        client.BaseAddress = new Uri("https+http://billingapi");
    });

I hope it solves your problem.

Reasons:
  • RegEx Blacklisted phrase (2.5): please send me
  • Contains signature (1):
  • Long answer (-1):
  • Has code block (-0.5):
Posted by: benjamin