The first service we'll want to register will be our HttpClientFactory. This class is an incredibly useful factory class that will provide managed instances of the HttpClient class. Prior to this wrapper class managing instances of HttpClient for us, there was actually a very painful and difficult-to-track-down bug that would arise when using common patterns for creating and disposing of instances of HttpClient by hand. Since the HttpClient class implements the IDisposable interface, many developers would instantiate it within the context of a using(var client = new HttpClient()) statement. While this is the recommended pattern for almost every other class that implements IDisposable, in the specific case of ...
The IHttpClientFactory class
Get Hands-On Network Programming with C# and .NET Core now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.