-
Notifications
You must be signed in to change notification settings - Fork 571
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
Is there any way to use ServiceDiscovery for client (aka browser) apps? #1536
Comments
The service discovery system requires configuration to have the service name mapped to the actual underlying endpoint address. For server apps composed into the Aspire AppHost project, this happens automatically by injecting environment variables into the processes when they start, that have names that follow the service discovery system's configuration-based provider (and because ASP.NET Core configuration defaults to reading from environment variables, it works). For browser apps, there's no such automatic flowing of configuration for service discovery. You'll need to somehow flow the configuration details to the browser. If the HTML is initially server-rendered, you could emit the details there into the page in some format, e.g. I might have a go at putting together a sample as this question has come up a few times and it would be good to have something to point at. |
@DamianEdwards maybe it would be nice to have a example how to host static content in aspire. Or what is the best way. I mean you can always deploy some kind of static website server but there are so many options out there that it could be a bit overwhelming to choose and also to build a good integration for it to aspire. |
Service Discovery does not support client-side apps today since, as @DamianEdwards said, there is no automatic flowing of configuration from the host to the client application. In the eShop sample, we use YARP to act as a proxy when the client needs to contact another service. In particular, loading images from the catalog: https://github.com/dotnet/eShop/blob/3b49f61a888656b038b5f044b0d4c5096fc9f073/src/WebApp/Program.cs#L29 For the MAUI frontend, we map each API which is needed by the app using a similar strategy here: https://github.com/dotnet/eShop/blob/3b49f61a888656b038b5f044b0d4c5096fc9f073/src/Mobile.Bff.Shopping/Program.cs#L12-L36 EDIT to clarify: in the eShop sample, instead of the clients communicating directly with backend API services, they only communicate directly with the service which the app is hosted on. That service proxies communication to the correct backend, using service discovery. |
Is anything special needed to be done for the forwarder to make it work with Aspire's service discovery, e.g. I have added the following forwarder to Wasm Server:
but I get the following error:
If I implement a new API in the server, and use |
@yarseyah yes, add a reference to Microsoft.Extensions.ServiceDiscovery.Yarp, and call |
@davidfowl, as far as I can tell, adding a reference to Trying to add
|
@1iveowl that package would be added to the server project in the case of an ASP.NET Core hosted Blazor WASM project, if using YARP to forward requests from the Blazor WASM app to another backend service. |
I believe this pull request (if it gets accepted) will do what you need with service discovery, @paule96. In the meantime, this Nuget package does exactly the same thing for you. It doesn't make the Aspire developer experience with Blazor totally seamless, but it does overcome your particular problem. I'd be glad of feedback on the repo if you decide to try it. |
Hi aspire team,
in my last try to use aspire I tried to add a blazor webassembly app to my project.
What I did so far is the following:
Add the blazor project to the aspire host with a reference to the backend:
Now I added the required packages to get service discovery to my blazor project
Then I added in my
Program.cs
of my blazor project the following lines:Then I use as
BaseAddress
for myhttpClient
http://elsaServer/elsa/api
But when I run my blazor application I always get a HTTP Request from the browser on
http://elsaServer/elsa/api
and not onhttp://localhost:43432/elsa/api
.Something seems to not work here. And I don't know how to fix it.
So what I would wish to do is something like:
So you can specify in you client apps where aspire lives and provide an API that the clients can use to discover the services
The text was updated successfully, but these errors were encountered: