Microsoft.Extensions.Http.Polly 10.0.0-preview.3.25172.1

About

Microsoft.Extensions.Http.Polly integrates IHttpClientFactory with the Polly library to provide comprehensive resilience and transient fault-handling. It allows developers to express policies such as Retry, Circuit Breaker, Timeout, Bulkhead Isolation, and Fallback in a fluent and thread-safe manner.

[!NOTE] This package is deprecated. Please use either Microsoft.Extensions.Resilience or Microsoft.Extensions.Http.Resilience instead.

How to Use

To use Microsoft.Extensions.Http.Polly, follow these steps:

Installation

dotnet add package Microsoft.Extensions.Http.Polly

Usage

Handle transient faults

AddTransientHttpErrorPolicy can be used define a policy that handles transient errors:

builder.Services.AddHttpClient("PollyWaitAndRetry")
    .AddTransientHttpErrorPolicy(policyBuilder =>
        policyBuilder.WaitAndRetryAsync(
            retryCount: 3,
            retryNumber => TimeSpan.FromMilliseconds(600)));

In the preceding example, failed requests are retried up to three times with a delay of 600 ms between attempts.

Dynamically select policies

To dynamically inspect a request and decide which policy apply, use the AddPolicyHandler extension method:

var timeoutPolicy = Policy.TimeoutAsync<HttpResponseMessage>(
    TimeSpan.FromSeconds(10));
var longTimeoutPolicy = Policy.TimeoutAsync<HttpResponseMessage>(
    TimeSpan.FromSeconds(30));

builder.Services.AddHttpClient("PollyDynamic")
    .AddPolicyHandler(httpRequestMessage =>
        httpRequestMessage.Method == HttpMethod.Get
            ? timeoutPolicy
            : longTimeoutPolicy);

In this example, if the outgoing request is an HTTP GET, a 10-second timeout is applied. For any other HTTP method, a 30-second timeout is used.

Main Types

The main types provided by this package are:

  • PollyHttpClientBuilderExtensions: Provides extension methods for configuring PolicyHttpMessageHandler message handlers as part of an HttpClient message handler pipeline
  • PolicyHttpMessageHandler: A DelegatingHandler implementation that executes request processing surrounded by a Polly.Policy
  • PollyServiceCollectionExtensions: Provides convenience extension methods to register Polly.Registry.IPolicyRegistry<string> and Polly.Registry.IReadOnlyPolicyRegistry<string> in a service collection
  • HttpRequestMessageExtensions: Provides extension methods for HttpRequestMessage Polly integration

Additional Documentation

For additional documentation and examples, refer to the official documentation on using Polly-based handlers in ASP.NET Core.

Feedback & Contributing

Microsoft.Extensions.Http.Polly is released as open-source under the MIT license. Bug reports and contributions are welcome at the GitHub repository.

Showing the top 20 packages that depend on Microsoft.Extensions.Http.Polly.

Packages Downloads
Microsoft.Extensions.Http.Resilience
Resilience mechanisms for HTTP Client.
9
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
9
OpenIddict.Client.SystemNetHttp
System.Net.Http integration package for the OpenIddict client services.
10
OpenIddict.Validation.SystemNetHttp
System.Net.Http integration package for the OpenIddict validation services.
9

.NET Standard 2.0

Version Downloads Last updated
10.0.0-preview.3.25172.1 5 04/12/2025
10.0.0-preview.2.25164.1 8 03/31/2025
10.0.0-preview.1.25120.3 8 04/01/2025
9.0.4 5 04/11/2025
9.0.3 8 04/01/2025
9.0.2 8 04/01/2025
9.0.1 8 04/01/2025
9.0.0 8 04/01/2025
9.0.0-rc.2.24474.3 8 04/01/2025
9.0.0-rc.1.24452.1 8 04/01/2025
9.0.0-preview.7.24406.2 8 04/01/2025
9.0.0-preview.6.24328.4 7 04/01/2025
9.0.0-preview.5.24306.11 8 04/01/2025
9.0.0-preview.4.24267.6 8 04/01/2025
9.0.0-preview.3.24172.13 7 04/01/2025
9.0.0-preview.2.24128.4 8 04/01/2025
9.0.0-preview.1.24081.5 8 04/01/2025
8.0.15 5 04/10/2025
8.0.14 8 04/01/2025
8.0.13 8 04/01/2025
8.0.12 8 04/01/2025
8.0.11 8 04/01/2025
8.0.10 8 04/01/2025
8.0.8 8 04/01/2025
8.0.7 8 04/01/2025
8.0.6 8 04/01/2025
8.0.5 8 04/01/2025
8.0.4 6 04/07/2025
8.0.3 9 04/03/2025
8.0.2 8 04/01/2025
8.0.1 8 04/01/2025
8.0.0 8 04/01/2025
8.0.0-rc.2.23480.2 8 04/01/2025
8.0.0-rc.1.23421.29 8 04/01/2025
8.0.0-preview.7.23375.9 8 04/01/2025
8.0.0-preview.6.23329.11 8 04/01/2025
8.0.0-preview.5.23302.2 9 04/01/2025
8.0.0-preview.4.23260.4 8 04/01/2025
8.0.0-preview.3.23177.8 8 04/01/2025
8.0.0-preview.2.23153.2 8 04/01/2025
8.0.0-preview.1.23112.2 8 04/01/2025
7.0.20 8 04/01/2025
7.0.19 8 04/01/2025
7.0.18 8 04/01/2025
7.0.17 8 04/01/2025
7.0.16 8 04/01/2025
7.0.15 8 04/01/2025
7.0.14 7 04/01/2025
7.0.13 8 04/01/2025
7.0.12 7 04/01/2025
7.0.11 8 04/01/2025
7.0.10 8 04/01/2025
7.0.9 8 04/01/2025
7.0.8 8 04/01/2025
7.0.7 8 04/01/2025
7.0.5 8 04/01/2025
7.0.4 8 04/01/2025
7.0.3 8 04/01/2025
7.0.2 8 04/01/2025
7.0.1 8 04/01/2025
7.0.0 7 04/01/2025
7.0.0-rc.2.22476.2 8 04/01/2025
7.0.0-rc.1.22427.2 8 04/01/2025
7.0.0-preview.7.22376.6 8 04/01/2025
7.0.0-preview.6.22330.3 8 04/01/2025
7.0.0-preview.5.22303.8 8 04/01/2025
7.0.0-preview.4.22251.1 7 04/01/2025
7.0.0-preview.3.22178.4 8 04/01/2025
7.0.0-preview.2.22153.2 8 04/01/2025
7.0.0-preview.1.22109.13 8 04/01/2025
6.0.36 8 04/01/2025
6.0.35 8 04/01/2025
6.0.33 8 04/01/2025
6.0.32 8 04/01/2025
6.0.31 8 04/01/2025
6.0.30 8 04/01/2025
6.0.29 8 04/01/2025
6.0.28 8 04/01/2025
6.0.27 7 04/01/2025
6.0.26 8 04/01/2025
6.0.25 8 04/01/2025
6.0.24 8 04/01/2025
6.0.23 7 04/01/2025
6.0.22 8 04/01/2025
6.0.21 8 04/01/2025
6.0.20 8 04/01/2025
6.0.19 8 04/01/2025
6.0.18 8 04/01/2025
6.0.16 8 04/01/2025
6.0.15 8 04/01/2025
6.0.14 8 04/01/2025
6.0.13 7 04/01/2025
6.0.12 8 04/01/2025
6.0.11 8 04/01/2025
6.0.10 9 04/01/2025
6.0.9 6 04/06/2025
6.0.8 8 04/01/2025
6.0.7 8 04/01/2025
6.0.6 8 04/01/2025
6.0.5 8 04/01/2025
6.0.4 8 04/01/2025
6.0.3 8 04/01/2025
6.0.2 8 04/01/2025
6.0.1 7 04/01/2025
6.0.0 8 04/01/2025
6.0.0-rc.2.21480.10 8 04/01/2025
6.0.0-rc.1.21452.15 8 04/01/2025
6.0.0-preview.7.21378.6 8 04/01/2025
6.0.0-preview.6.21355.2 8 04/01/2025
6.0.0-preview.5.21301.17 8 04/01/2025
6.0.0-preview.4.21253.5 8 04/01/2025
6.0.0-preview.3.21201.13 8 04/01/2025
6.0.0-preview.2.21154.6 8 04/01/2025
6.0.0-preview.1.21103.6 5 04/07/2025
5.0.1 8 04/01/2025
5.0.0 8 04/01/2025
5.0.0-rc.2.20478.4 8 04/01/2025
5.0.0-rc.1.20451.7 8 04/01/2025
5.0.0-preview.8.20407.3 8 04/01/2025
5.0.0-preview.7.20365.4 8 04/01/2025
5.0.0-preview.6.20306.1 8 04/01/2025
5.0.0-preview.5.20278.3 8 04/01/2025
5.0.0-preview.4.20251.2 8 04/01/2025
5.0.0-preview.3.20215.2 8 04/01/2025
5.0.0-preview.2.20160.3 8 04/01/2025
5.0.0-preview.1.20120.4 8 04/01/2025
3.1.32 8 04/01/2025
3.1.31 8 04/01/2025
3.1.30 8 04/01/2025
3.1.29 8 04/01/2025
3.1.28 8 04/01/2025
3.1.27 8 04/01/2025
3.1.26 8 04/01/2025
3.1.25 8 04/01/2025
3.1.24 8 04/01/2025
3.1.23 8 04/01/2025
3.1.22 8 04/01/2025
3.1.21 8 04/01/2025
3.1.20 8 04/01/2025
3.1.19 8 04/01/2025
3.1.18 8 04/01/2025
3.1.17 7 04/01/2025
3.1.16 8 04/01/2025
3.1.15 8 04/01/2025
3.1.14 8 04/01/2025
3.1.13 8 04/01/2025
3.1.12 8 04/01/2025
3.1.11 8 04/01/2025
3.1.10 8 04/01/2025
3.1.9 8 04/01/2025
3.1.8 8 04/01/2025
3.1.7 8 04/01/2025
3.1.6 8 04/01/2025
3.1.5 9 04/01/2025
3.1.4 8 04/01/2025
3.1.3 8 04/01/2025
3.1.2 8 04/01/2025
3.1.1 8 04/01/2025
3.1.0 8 04/01/2025
3.1.0-preview3.19553.2 8 03/31/2025
3.1.0-preview2.19525.4 7 04/01/2025
3.1.0-preview1.19506.1 8 04/01/2025
3.0.3 8 04/01/2025
3.0.2 8 04/01/2025
3.0.1 8 04/01/2025
3.0.0 8 04/01/2025
3.0.0-rc1.19456.10 8 04/01/2025
3.0.0-preview9.19423.4 8 04/01/2025
3.0.0-preview8.19405.4 8 04/01/2025
3.0.0-preview7.19362.4 8 04/01/2025
3.0.0-preview6.19304.6 8 04/01/2025
3.0.0-preview5.19227.9 7 04/01/2025
3.0.0-preview4.19216.2 8 04/01/2025
3.0.0-preview3.19153.1 8 04/01/2025
3.0.0-preview.19074.2 8 04/01/2025
3.0.0-preview.18572.1 8 03/31/2025
2.2.0 8 04/01/2025
2.2.0-preview3-35497 8 04/01/2025
2.2.0-preview2-35157 7 04/01/2025
2.2.0-preview1-35029 8 04/01/2025
2.1.1 7 04/01/2025
2.1.0 8 04/01/2025
2.1.0-rc1-final 8 03/31/2025
2.1.0-preview2-final 8 03/31/2025