Microsoft.Extensions.Http.Polly 10.0.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
Volo.Abp.Http.Client
Package Description
9
Volo.Abp.Http.Client
Package Description
8
Volo.Abp.Http.Client
Package Description
7
Volo.Abp.Http.Client
Package Description
6
Volo.Abp.Http.Client
Package Description
5

.NET Standard 2.0

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