-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Keyed services aren't working with HttpClientBuilder #89446
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionIt seems that Reproduction Stepsvar services = new ServiceCollection();
var httpClientBuilder = services
.AddHttpClient("named");
httpClientBuilder.Services.TryAddKeyedSingleton<MyClientLogger>(httpClientBuilder.Name);
httpClientBuilder.AddLogger(sp => sp.GetRequiredKeyedService<HttpClientLogger>(httpClientBuilder.Name));
using var provider = services.BuildServiceProvider();
var httpClientFactory = provider.GetRequiredService<IHttpClientFactory>();
using var httpClient = httpClientFactory.CreateClient("named"); And Expected behaviorNo exception is thrown. Actual behavior
Stack Trace:
Regression?No response Known WorkaroundsNo response Configuration.NET SDK Other informationI haven't tried, but the same issue could probably be the case when
|
UPD: there's no issue with ConfigueHttpClientDefaults, see comment below |
So, thinking this through, there's actually no second issue. ConfigueHttpClientDefaults utilize a proxy service collection, not a service provider. There's no problem with that, the interface should only be implemented by a service provider. I've checked that keyed services work just fine with a custom service collection. |
@xakep139 I'm considering closing this as a duplicate of #89447, as there's nothing needs to be changed in HttpClientFactory. Sadly there's no workaround I see, even suppressing scopes wouldn't help 😢 #89447 (comment) |
Duplicate of #89447 |
Description
It seems that
IHttpClientFactory
doesn't support newly added #64427.Reproduction Steps
And
MyLogger
simply implementsIHttpClientLogger
.Expected behavior
No exception is thrown.
Actual behavior
System.InvalidOperationException
is thrown with the next message:This service provider doesn't support keyed services.
Stack Trace:
Regression?
No response
Known Workarounds
No response
Configuration
.NET SDK
8.0.100-preview.7.23360.1
I was referencing runtime packages with version
8.0.0-rc.1.23373.2
.Other information
I haven't tried, but the same issue could probably be the case when
ConfigureHttpClientDefaults()
is used and in itsconfigure
action a keyed service is registered/resolved.The text was updated successfully, but these errors were encountered: