Adding a typed HTTP client twice, throws exception
See original GitHub issueEDIT by @rynowak - see below for shiproom template.
Calling
services.AddHttpClient<SomeType>()
more than once throws an exception in 3.0 preview 7 - this used to work in 2.x.
Is that the intended behavior?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
Do repeated calls to AddHttpClient overwrite each other?
But I am not sure if this means that the previous entry was overwritten. Can the same named client be "added" separately? Or...
Read more >HttpClient sends the same request twice in some cases
Description. After these steps HttpClient tries to re-establish TCP connection to server and sends the same request again. or (if netcat starts ...
Read more >Adding Resilience and Transient Fault handling to your . ...
Core 2.1 I moved my Http Client instances over to be created by the new HttpClientFactory. Now I have a single central place...
Read more >Handle errors in ASP.NET Core web APIs
Learn about error handling with ASP.NET Core web APIs.
Read more >Deserialise Json and Read Stream twice in C# - ...
I was think a lot that should I write this answer or not. I don't want to be rude or offensive, but this...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Description
In 3.0 we added validation to HttpClient Factory’s registration code path to prevent some common mistakes. This new validation code blocks some valid use cases that we didn’t know about.
Customer Impact
Attempting to call
AddHttpClient<T>
twice with the sameT
throws an exception. This pattern is used when both library code and user code want to collaborate on configuration of a client type.Regression?
Yes, this is a regression from 2.2
Risk
Low. This add special casing to our validation code path to allow more patterns. The impact of this is that cases that are explicitly blocked by an exception in 3.0 (but were allowed in 2.2) will be allowed again.
We’ve just stumbled into this issue after upgrading our projects from 2.2 to 3.1. In 2.2, we were relying on the ability to call
AddHttpClient<T>()
subsequent times, e.g. in.ConfigureTestServices()
to override anHttpClient
’s message handler in tests.