Should HttpClient instances created by HttpClientFactory be disposed?

Calling the Dispose method is not required but you can still call it if you need for some reasons. Proof: HttpClient and lifetime management Disposal of the client isn’t required. Disposal cancels outgoing requests and guarantees the given HttpClient instance can’t be used after calling Dispose. IHttpClientFactory tracks and disposes resources used by HttpClient instances. … Read more

How to mock the new HttpClientFactory in .NET Core 2.1 using Moq

The HttpClientFactory is derived from IHttpClientFactory Interface So it is just a matter of creating a mock of the interface var mockFactory = new Mock<IHttpClientFactory>(); Depending on what you need the client for, you would then need to setup the mock to return a HttpClient for the test. This however requires an actual HttpClient. var … Read more