What should be the HttpClient
lifetime of a WebAPI client?
Is it better to have one instance of the HttpClient
for multiple calls?
Wh
You may also want to refer to this blog post by Simon Timms: https://aspnetmonsters.com/2016/08/2016-08-27-httpclientwrong/
But
HttpClient
is different. Although it implements theIDisposable
interface it is actually a shared object. This means that under the covers it is reentrant) and thread safe. Instead of creating a new instance ofHttpClient
for each execution you should share a single instance ofHttpClient
for the entire lifetime of the application. Let’s look at why.