Polly v8 resilience pipelines with Microsoft.Extensions.Http.Resilience. Retry, timeout, fallback, hedging, and composable strategies. Trigger: Polly, resilience, resilience pipeline, HTTP resilience, fault tolerance.
From dotnet-ai-kitnpx claudepluginhub faysilalshareef/dotnet-ai-kit --plugin dotnet-ai-kitThis skill uses the workspace's default tool permissions.
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Delivers DB-free sandbox API regression tests for Next.js/Vitest to catch AI blind spots in self-reviewed code changes like API routes and backend logic.
Microsoft.Extensions.Http.Resilience for HTTP client resilience (Polly v8)AddStandardResilienceHandler() for sensible defaults// Applies retry + circuit breaker + total timeout out of the box
builder.Services.AddHttpClient("OrdersApi", client =>
{
client.BaseAddress = new Uri("https://api.orders.{Company}.com");
})
.AddStandardResilienceHandler();
builder.Services.AddHttpClient("PaymentGateway", client =>
{
client.BaseAddress = new Uri("https://payments.example.com");
})
.AddResilienceHandler("payment-pipeline", pipeline =>
{
// Retry with exponential backoff + jitter
pipeline.AddRetry(new HttpRetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromMilliseconds(500),
BackoffType = DelayBackoffType.Exponential,
UseJitter = true,
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
.HandleResult(r =>
r.StatusCode == HttpStatusCode.TooManyRequests ||
r.StatusCode >= HttpStatusCode.InternalServerError)
});
// Circuit breaker
pipeline.AddCircuitBreaker(new HttpCircuitBreakerStrategyOptions
{
FailureRatio = 0.5,
SamplingDuration = TimeSpan.FromSeconds(30),
MinimumThroughput = 10,
BreakDuration = TimeSpan.FromSeconds(15)
});
// Timeout per attempt
pipeline.AddTimeout(TimeSpan.FromSeconds(5));
});
// For database, message queue, or other non-HTTP operations
builder.Services.AddResiliencePipeline("database-retry", pipeline =>
{
pipeline
.AddRetry(new RetryStrategyOptions
{
MaxRetryAttempts = 3,
Delay = TimeSpan.FromSeconds(1),
BackoffType = DelayBackoffType.Exponential,
ShouldHandle = new PredicateBuilder()
.Handle<SqlException>()
.Handle<TimeoutException>()
})
.AddTimeout(TimeSpan.FromSeconds(30));
});
// Consuming via DI
public sealed class DataService(
[FromKeyedServices("database-retry")] ResiliencePipeline pipeline,
IDbConnectionFactory connectionFactory)
{
public async Task<Order?> GetOrderAsync(
Guid id, CancellationToken ct)
{
return await pipeline.ExecuteAsync(async token =>
{
using var conn = connectionFactory.CreateConnection();
return await conn.QuerySingleOrDefaultAsync<Order>(
"SELECT * FROM Orders WHERE Id = @Id",
new { Id = id });
}, ct);
}
}
// Pipeline with typed result
builder.Services.AddResiliencePipeline<string, HttpResponseMessage>(
"external-api", pipeline =>
{
pipeline
.AddRetry(new RetryStrategyOptions<HttpResponseMessage>
{
MaxRetryAttempts = 2,
ShouldHandle = new PredicateBuilder<HttpResponseMessage>()
.HandleResult(r => !r.IsSuccessStatusCode)
})
.AddTimeout(TimeSpan.FromSeconds(10));
});
builder.Services.AddResiliencePipeline<string, OrderResponse?>(
"order-with-fallback", pipeline =>
{
pipeline
.AddFallback(new FallbackStrategyOptions<OrderResponse?>
{
FallbackAction = _ =>
Outcome.FromResultAsValueTask<OrderResponse?>(null),
ShouldHandle = new PredicateBuilder<OrderResponse?>()
.Handle<HttpRequestException>()
.Handle<TimeoutRejectedException>()
})
.AddRetry(new RetryStrategyOptions<OrderResponse?>
{
MaxRetryAttempts = 2
})
.AddTimeout(TimeSpan.FromSeconds(5));
});
// Send parallel requests to reduce tail latency
builder.Services.AddHttpClient("search-api")
.AddResilienceHandler("hedging", pipeline =>
{
pipeline.AddHedging(new HttpHedgingStrategyOptions
{
MaxHedgedAttempts = 2,
Delay = TimeSpan.FromMilliseconds(200)
});
});
Request → Fallback → Retry → Circuit Breaker → Timeout → HTTP Call
↓
Response
Strategies execute from outermost (first added) to innermost (last added).
Microsoft.Extensions.Http.Resilience packageAddStandardResilienceHandler callsAddResilienceHandler or AddResiliencePipeline callsPolly package (v7 — migration candidate)ResiliencePipeline injectionMicrosoft.Extensions.Http.Resilience| Strategy | Use When |
|---|---|
| Standard resilience handler | Default for all HTTP clients |
| Custom retry | Specific error codes or delay requirements |
| Circuit breaker | Downstream service prone to cascading failure |
| Timeout | Preventing indefinite waits |
| Fallback | Returning cached/default data when service is down |
| Hedging | Latency-sensitive operations with redundant backends |