I know you can register an IAsyncPolicy<HttpResponseMessage>
to a particular instance of an HttpClient
injected into a service, but is there a way to configure this globally, to all HttpClients wired up via microsofts dependency injection?
For example, you can wire up the HttpClient injected into MyService
via:
services.AddHttpClient<MyService>(
.AddPolicyHandler(
HttpPolicyExtensions
.HandleTransientHttpError()
.WaitAndRetryAsync(3, retryAttempt =>
TimeSpan.FromSeconds(Math.Pow(2, retryAttempt))));
But I would like to add this policy handler to all HttpClients. The class that I would like to add retries to is 3rd party and marked as internal, so I cannot directly access it.