Home > other >  Polly.Extensions.Http not accessible for IHttpClientFactory - .Net6
Polly.Extensions.Http not accessible for IHttpClientFactory - .Net6

Time:05-09

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!

enter image description here

I use these refrence

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 the HttpClientFactory is described in the wiki of the Polly github. It seems to use Microsoft.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)
}));
  • Related