I need to use Polly.Extensions.Http for same reason.
I install Polly and Polly.Extensions.Http packages, and have these using's
global using Polly;
global using Polly.Retry;
global using Polly.Timeout;
global using Polly.Extensions.Http;
but when need add to HttpClient, It's not available!
CodePudding user response:
To summarize the discussion in the comments:
- Like Peter Csala said: "The
Polly.Extensions.Http
package is deprecated. It has not been modified more than 3 years." - The new way to use
Polly
with theHttpClientFactory
is described in the wiki of thePolly
github. It seems to useMicrosoft.Extensions.Http.Polly
.
E.g.
services.AddHttpClient("GitHub", client =>
{
client.BaseAddress = new Uri("https://api.github.com/");
client.DefaultRequestHeaders.Add("Accept", "application/vnd.github.v3 json");
})
.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(5),
TimeSpan.FromSeconds(10)
}));