Scenario is I have an external HTTP service that I want to connect to (similar to an existing Redis instance or existing PostgreSQL instance) so I want to model it in my hosting project so that other resources can reference it and have service discovery configured so they can refer to it by the name I give it.
e.g.
MyApp.AppHost/Program.cs
var builder = DistributedApplication.CreateBuilder(args);
var weatherApi = builder.AddHttpService("weatherapi", "http://weather.internal.sda76erh.us.contoso.com");
builder.AddProject<Projects.Frontend>("frontend")
.WithReference(weatherApi);
builder.Build().Run();
MyApp.Frontend/Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.AddServiceDefaults();
builder.Services.AddHttpClient("weather", c => c.BaseAddress = new("http://weatherapi"));
var app = builder.Build();
app.MapGet("/", async (IHttpClientFactory hcf) => await hcf.CreateClient("weather").GetStringAsync("/weatherforecast"));
app.MapDefaultEndpoints();
app.Run();
Scenario is I have an external HTTP service that I want to connect to (similar to an existing Redis instance or existing PostgreSQL instance) so I want to model it in my hosting project so that other resources can reference it and have service discovery configured so they can refer to it by the name I give it.
e.g.
MyApp.AppHost/Program.cs
MyApp.Frontend/Program.cs