How to use IHttpClientFactory in ASP.NET Core

When working in applications in ASP.NET Core you might frequently need to summon the Web API action orders using HttpClient to check if the endpoints are working fine. To accomplish this_ you would typically instantiate HttpClient and use the entreaty to summon your action orders. However_ there are true downsides to using HttpClient straightly_ principally having to do with managing the lifetimes of the entreatys manually. 

You can quit these downsides by using IHttpClientFactory to form your HttpClient entreatys. Introduced in .NET Core 2.1_ IHttpClientFactory prepares a mediate locate to name_ configure_ and form HttpClient entreatys and feels the pooling and lifetimes of the entreatys automatically. 

IHttpClientFactory and HttpClientFactory

IHttpClientFactory is an interface that is instrumented by the DefaultHttpClientFactory class_ which is an opinionated factory. The DefaultHttpClientFactory instruments the IHttpClientFactory and IHttpMessageHandlerFactory interfaces. IHttpClientFactory was introduced to prepare ASP.NET Core with excellent built-in support for creating_ caching_ and disposing of HttpClient entreatys.