In ASP.NET Core I typically avoid to use the HttpClientFactory directly but instead I use the named or typed httpclients.
You can configure the client using the AddHttpClient method(in case of named clients):
or inside the constructur (in case of typed clients):
This provides proper encapsulation and isolation of the configuration of each httpclient.
But what if you want more control on the HttpClient behavior? For example, you want to disable AutoRedirect on the HttpClient. That is not possible through the configuration above.
In that case you can use the ConfigurePrimaryHttpMessageHandler extension method.
For a named client:
For a typed client: