Uh oh!
There was an error while loading. Please reload this page.
Add AddHttpClientDefaults - #87953
Conversation
ghost
commented
Jun 23, 2023
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
ghost
commented
Jun 23, 2023
Tagging subscribers to this area: @dotnet/ncl Issue DetailsFixes #87914 The The method:
|
davidfowl
commented
Jun 23, 2023
This feels pretty bad. |
@noahfalk@joperezr@geeknoid@davidfowl The The goal is to avoid having two methods:
For example, methods in dotnet/extensions below will no longer be needed: It will be possible to do: // Add HttpClientLogging to all clients.services.AddHttpClientDefaults().AddHttpClientLogging();// Is configured with HttpClientLogging from the defaults.services.AddHttpClient(); |
I've also been thinking about an API like this and was hoping we could add an overload to AddHttpClient so it wasnt 2 different calls. services.AddHttpClient(IHttpClientBuilder clientBuilder =>{clientBuilder.AddHttpMessageHandler<MyAuthHandler>();}); |
JamesNK
commented
Jun 23, 2023
It's not the best, but it works well. It hits these important requirements:
The extra logic is only applied to |
geeknoid
commented
Jun 23, 2023
@dpk83 FYI |
dpk83
commented
Jun 23, 2023
Uh oh!
There was an error while loading. Please reload this page.
stephentoub
commented
Jun 23, 2023
Let's please agree on the API via discussion on the issue and API review before opening PRs. I spoke with @CarnaViire at length about this and other related APIs yesterday and I know she was going to be following up with you. |
CarnaViire
left a comment
There was a problem hiding this comment.
LGTM for @JamesNK 's changes
CarnaViire
commented
Jul 12, 2023
@dotnet/ncl can someone pls review as well? Since I've taken over the PR. |
lewing
commented
Jul 17, 2023
This change appears to be breaking flow into aspnetcore in dotnet/aspnetcore#49433 |
joperezr
commented
Jul 17, 2023
@CarnaViire can you please take a look? |
CarnaViire
commented
Jul 17, 2023
I've pushed the fix to the branch dotnet/aspnetcore#49433 |
davidfowl
commented
Aug 22, 2023
So we have a problem here. I tried to use ConfigureHttpClientDefaults and noticed it isn't an extension method in the reference assembly. |
joperezr
commented
Aug 22, 2023
Can you elaborate? This change seems to suggest that the reference assembly was edited and that the extension was properly added: https://github.com/dotnet/runtime/pull/87953/files#diff-06e422c9663ed696b723dc56832cbdb53b9f9c3e6d0a98e52a1cb081b7c9dc7aR50 |
karelz
commented
Aug 22, 2023
joperezr
commented
Aug 22, 2023
Oh, completely missed it! Good catch @davidfowl and thanks for the quick fix 😃 |
Fixes#87914
The
AddHttpClientDefaultsmethod supports adding configuration to all createdHttpClients.The method:
Microsoft.Extensions.Configurationautomatically applies configuration with a null name to all named configuration.IServiceCollection. This is to make it so the order ofAddHttpClientDefaultsandAddHttpClientdoesn't matter. Default config is always applied first, then named config is applied after. This is done by wrapping theIServiceCollectionin an implementation that modifies the order thatIConfigureOptions<HttpClientFactoryOptions>values are added.