-
Notifications
You must be signed in to change notification settings - Fork 570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aspire doesn't replace http client Uri with actual address in blazor webassembly standalone app because it don't have appsettings.json #4785
Comments
Have you added Service discovery doesn't work on the Wasm side, you need to look into |
@yarseyah I tried to add |
I'm not sure there are any Aspire components that make sense for the Blazor Wasm. You can add service discovery, etc., to the Blazor Server, but your client is entirely standalone—you want to send your API calls to the server and have the server, via Yarp, redirect your requests to the API. |
If your client project is still If you want to try it on your project https://learn.microsoft.com/de-de/aspnet/core/migration/70-80?view=aspnetcore-9.0&tabs=visual-studio |
Doesnt that just make the application run server side? |
I had the same requirement as described above. Yes, you can add the URLs to web APIs that your Blazor WebAssembly (client) app needs to call in the client's appsettings.json files, and that works ok. You can even specify different URLs in for different environments in appSettings.{environmentName}.json and that works fine too. However, you'll have to remember to maintain the endpoints in the client app if they change in the distributed app, and that's exactly the pain-point that Aspire is designed to address. I made a Nuget package that expands the existing functionality of Aspire to work for Blazor WebAssembly (client) apps: If you install the Nuget package in your AppHost project and follow the instructions in the README.md then your distributed application host will put the service discovery information in the appropriate appsettings.{environment}.json file of the Blazor WebAssembly (client) app. I've targeted .NET 8 and 9. It's only five more classes and it doesn't change any of the existing codebase of Aspire. Please can you let me know if you like the implementation and contribute improvements on GitHub if you wish? It's as simple as the below (in Program.cs of your AppHost project)
Then in Program.cs of the client app:
|
I've just sent a pull request to the Aspire team to integrate the Aspire4Wasm functionality into the framework. It's here: #7162 I said:
Maybe this will get accepted and prompt further improvements for Blazor developers working with Aspire. I believe Aspire makes perfect sense for Blazor Wasm and the two technologies could work very well together given the chance. |
Describe the bug
i referenced the blazor project to Aspire app host so this is my aspire app host code
and this is my blazor code to add HTTP client
so as you can see in the result it doesn't replace the

http://identityserverapi
with the actual addressand also i found the
builder.Configuration.GetConnectionString("identityserverapi");
doesn't work because we don't haveappsettings.json
in blazor wasm so i think Aspire doesn't work fo the blazor wasmThe text was updated successfully, but these errors were encountered: