AddDaprClient incompatible with keyed services
onionhammer opened this issue · comments
Expected Behavior
When adding dapr client to service builder, this should not error
https://weblogs.asp.net/ricardoperes/net-8-dependency-injection-changes-keyed-services
// Add dapr client
builder.Services.AddDaprClient(client =>
{
client.UseJsonSerializationOptions(JsonExtensions.JsonOptions);
});
Actual Behavior
When adding dapr to your serviceBuilder, if there are keyed services present, adding dapr fils with exception:
Unhandled exception. System.InvalidOperationException: This service descriptor is keyed. Your service provider may not support keyed services.
Steps to Reproduce the Problem
Add a dapr client to an application with keyed services defined, i.e. with Orleans:
builder.Host.UseOrleans(siloBuilder =>
{
siloBuilder.AddActivityPropagation();
});
builder.AddServiceDefaults();
builder.Services.AddDaprClient();
System.InvalidOperationException
HResult=0x80131509
Message=This service descriptor is keyed. Your service provider may not support keyed services.
Source=Microsoft.Extensions.DependencyInjection.Abstractions
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.ThrowKeyedDescriptor()
at Microsoft.Extensions.DependencyInjection.ServiceDescriptor.get_ImplementationType()
at Microsoft.Extensions.DependencyInjection.DaprServiceCollectionExtensions.<>c.b__0_0(ServiceDescriptor s)
at System.Linq.Enumerable.Any[TSource](IEnumerable1 source, Func
2 predicate)
at Microsoft.Extensions.DependencyInjection.DaprServiceCollectionExtensions.AddDaprClient(IServiceCollection services, Action`1 configure)
at Insights.Worker.Manager.Program.Main(String[] args) in D:\Trade\InsightsOnDaprAspire\src\Workers\Manager\Program.cs:line 15
For the contributors, here's a PR that addresses this in Microsoft.Identity.Web, for reference:
Guys!
We really need this for .NET Aspire. Do you have any update when We can expect to have this fixed?
Thank you!
Thank you @Sen-Gupta.
The issue is not with AddDapr
but with AddDaprClient
.
This happens with the newest .NET Aspire Preview 3.
From further investigation, we found out that the offending dependency is with library Microsoft.Extensions.Http.Resilience
when updated from version 8.1.0
to 8.2.0
. Hope it helps.
Double Confirmation!
That's correct. I did upgrade Microsoft.Extensions.Http.Resilience to 8.2.0.