Aspire와 WASM이 지원되지 않는 이슈 해결기

Aspire를 지속적으로 가지고 놀면서 이것저것 다루던 와중, 기묘한 현상에 부딪치게 되어 우회할 수 있는 방법이 발견되어 공유드립니다.

해당글과 몇몇 유명한 닷넷 유튜버 MS를 보고 따라하던 와중 예상치도 못하게 Blazor WASM은 Aspire 리소스에서 검색하도록 지원을 하지 않는다 였습니다.
(이걸 진작 파악하지 못한 이유는 Rider에서 디버깅모드가 아닌 Run 상태로 주로 쓰다보니 구동이 되고 실제 통신이 되다가, 무언가 막히게 되어 디버깅모드를 키는순간 안켜지면서 아차차… 이거뭔가 이상하다)

그러면서 찾아본결과

해당 레포의 도움을 받아서 해결하게 되었습니다.

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();

샘플로 작성한 Blazor라는 프로젝트가 뭐지하고는 한참 찾아본결과, 그냥


추가해서 해결했습니다.

이게 어찌 가능한가 했더니, 해당 레포에 설명이 있더군요.

.NET Aspire doesn’t currently (as of early 2025) facilitate a Blazor > WebAssembly (client) app discovering Aspire resources, even if the app has been added to the distributed application, because Blazor WebAssembly apps run in the browser and are “standalone”. This has been commented on here:

The expectation is that these apps will need to be aware of the web APIs they’re supposed to call without relying on Aspire, and that they will store these in appsettings.json or appsettings.{environmentName}.json. This works fine, but if the endpoint changes, or if it differs in your development and production environments, you have to remember to manage those changes in your client app as well as your other resources. This is precisely the problem Aspire is intended to solve.

My little library Aspire4Wasm solves the problem by writing the service discovery information to the appsettings.{environmentName}.json file of your client app for you.

결국 WASM이 브라우저에서 실행되고 독립형 이기때문에 라는게 주된이유고.
그에 따른 파생문제가 도메인의 변경등이 생겼을때, 문제가 되고 자기의 라이브러리를 통해 문제가 해결이 가능하다!

일단 해당 프로젝트가 개인이 만든 프로젝트라서 걱정이 많을 수는 있지만
Blazor wasm을 다루는 유저들의 토론이 진행되고 있으며

해당 유저가 git issue에도 등록할 정도로 열정적이라서 빠른시일내에 WASM을 지원하는 혹은 해당 레포가 Aspire에 포함될 수도 있을 것 같습니다!

3개의 좋아요

추가: 블레이저 wasm 이 실행되지 않는 이슈는 그냥 Chrome을 모두종료하고 재실행했더니 해결되었습니다.

!blazor.wasm.debug.exception.browser.empty!
오랜 고질병같은거더군요 ㅎㅎㅎ…

어제 제대로 파악하지 못한상태로 게시글을 작성하여, 저게 뭐가 좋은거지 라는 부분에 대해서 다시 설명드리자면

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");
    });

이런식으로 aspire에서 선언해준 이름 기준으로 appsettings를 자기가 만들어내서 http, https 혹은 포트변경에 따른 하나하나 수정할 필요가 없습니다!

4개의 좋아요