diff --git a/Directory.Packages.props b/Directory.Packages.props index 1a67edfdd..0b3c8fdc7 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -36,7 +36,7 @@ - + diff --git a/examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.ServiceA/Program.cs b/examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.ServiceA/Program.cs index 65c8cce2a..82e7297d3 100644 --- a/examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.ServiceA/Program.cs +++ b/examples/dapr/CommunityToolkit.Aspire.Hosting.Dapr.ServiceA/Program.cs @@ -10,6 +10,9 @@ // Add services to the container. builder.Services.AddDaprClient(); +builder.Services.AddHttpClient("serviceb", client => + client.BaseAddress = new Uri("http://serviceb")) + .AddHttpMessageHandler(() => new InvocationHandler()); var app = builder.Build(); @@ -17,7 +20,7 @@ app.UseCloudEvents(); app.MapSubscribeHandler(); -app.MapGet("/weatherforecast", async (DaprClient client) => +app.MapGet("/weatherforecast", async (DaprClient client, IHttpClientFactory httpClientFactory) => { var cachedForecasts = await client.GetStateAsync("statestore", "cache"); @@ -26,7 +29,9 @@ return cachedForecasts.Forecasts; } - var forecasts = await client.InvokeMethodAsync(HttpMethod.Get, "serviceb", "weatherforecast"); + var httpClient = httpClientFactory.CreateClient("serviceb"); + var forecasts = await httpClient.GetFromJsonAsync("/weatherforecast") + ?? throw new InvalidOperationException("Failed to retrieve weather forecasts from serviceb."); await client.SaveStateAsync("statestore", "cache", new CachedWeatherForecast(forecasts, DateTimeOffset.UtcNow));