Microsoft.Extensions.Http.Polly 10.0.0-preview.6.25358.103
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.ResilienceorMicrosoft.Extensions.Http.Resilienceinstead.
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 configuringPolicyHttpMessageHandlermessage handlers as part of anHttpClientmessage handler pipelinePolicyHttpMessageHandler: ADelegatingHandlerimplementation that executes request processing surrounded by aPolly.PolicyPollyServiceCollectionExtensions: Provides convenience extension methods to registerPolly.Registry.IPolicyRegistry<string>andPolly.Registry.IReadOnlyPolicyRegistry<string>in a service collectionHttpRequestMessageExtensions: Provides extension methods forHttpRequestMessagePolly 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.
|
5 |
.NET Standard 2.0
- Microsoft.Extensions.Http (>= 10.0.0-preview.6.25358.103)
- Polly (>= 7.2.4)
- Polly.Extensions.Http (>= 3.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 10.0.0-preview.6.25358.103 | 8 | 07/16/2025 |
| 9.0.7 | 7 | 07/14/2025 |
| 9.0.0-rc.2.24474.3 | 5 | 07/11/2025 |
| 9.0.0-preview.7.24406.2 | 5 | 07/09/2025 |
| 8.0.18 | 7 | 07/15/2025 |
| 8.0.16 | 5 | 07/10/2025 |
| 8.0.1 | 4 | 07/10/2025 |
| 8.0.0-rc.1.23421.29 | 5 | 07/12/2025 |
| 8.0.0-preview.5.23302.2 | 5 | 07/13/2025 |
| 8.0.0-preview.3.23177.8 | 5 | 07/09/2025 |
| 7.0.20 | 5 | 07/12/2025 |
| 7.0.13 | 5 | 07/12/2025 |
| 7.0.12 | 5 | 07/11/2025 |
| 7.0.10 | 5 | 07/10/2025 |
| 7.0.7 | 4 | 07/12/2025 |
| 7.0.0 | 4 | 07/10/2025 |
| 7.0.0-rc.1.22427.2 | 5 | 07/11/2025 |
| 7.0.0-preview.3.22178.4 | 5 | 07/11/2025 |
| 7.0.0-preview.2.22153.2 | 5 | 07/11/2025 |
| 6.0.32 | 5 | 07/09/2025 |
| 6.0.30 | 4 | 07/11/2025 |
| 6.0.28 | 5 | 07/10/2025 |
| 6.0.21 | 5 | 07/10/2025 |
| 6.0.16 | 5 | 07/09/2025 |
| 6.0.13 | 5 | 07/12/2025 |
| 6.0.0-preview.7.21378.6 | 5 | 07/09/2025 |
| 6.0.0-preview.6.21355.2 | 5 | 07/10/2025 |
| 6.0.0-preview.5.21301.17 | 5 | 07/09/2025 |
| 5.0.1 | 4 | 07/10/2025 |
| 5.0.0-rc.1.20451.7 | 5 | 07/11/2025 |
| 5.0.0-preview.6.20306.1 | 7 | 08/08/2025 |
| 3.1.31 | 6 | 07/11/2025 |
| 3.1.14 | 4 | 07/12/2025 |
| 3.1.12 | 4 | 07/10/2025 |