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

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
2
Volo.Abp.Http.Client
Package Description
1

.NET Standard 2.0

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