microsoft / microsoft/aspire

Is there any way to use ServiceDiscovery for client (aka browser) apps?

Open
#1,536 8 comments 7 reactions 1 assignee Claimed by @maraf View on GitHub
area-samples area-service-discovery blazor-wasm
Dominant language
C#
Stars
6.3k
Forks
991
Avg merge
2d 15h
Merged PRs (30d)
196

Description

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:

```csharp
using Aspire.Hosting;
var builder = DistributedApplication.CreateBuilder(args);

var server = builder.AddProject("elsaServer");
var webApp = builder.AddProject("elsaStudio")
.WithReference(server);

var app = builder.Build();
await app.RunAsync();
```

Now I added the required packages to get service discovery to my blazor project

```xml


```

Then I added in my `Program.cs` of my blazor project the following lines:

```csharp
builder.Services.AddServiceDiscovery();
builder.Services.ConfigureHttpClientDefaults(http =>
{
// Turn on resilience by default
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.UseServiceDiscovery();
});
```

Then I use as `BaseAddress` for my `httpClient` `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 on `http://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:

```csharp
builder.Services.AddServiceDiscovery("http://aspireHost/serviceDiscovery");
```

So you can specify in you client apps where aspire lives and provide an API that the clients can use to discover the services

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.