You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Azure Key Vault is a hard dependency for most production apps — connection failures at startup or runtime cause outages. This library adds Polly v8 resilience without boilerplate:
Problem
Solution
HTTP 429 throttling (Key Vault has strict rate limits)
Caught by KeyVaultTransientErrors.IsTransient
HTTP 503 during Key Vault maintenance / regional failover
Caught by KeyVaultTransientErrors.IsTransient
HTTP 504 gateway timeout
Caught by KeyVaultTransientErrors.IsTransient
HttpRequestException network failure
Caught by KeyVaultTransientErrors.IsTransient
TaskCanceledException slow response
Caught by KeyVaultTransientErrors.IsTransient
Cascading failures propagating to the rest of the app
// Program.cs / Startup.csbuilder.Services.AddSingleton(newSecretClient(newUri("https://my-vault.vault.azure.net/"),newDefaultAzureCredential()));builder.Services.AddPollyAzureKeyVault(pipeline =>pipeline.AddRetry(newRetryStrategyOptions{MaxRetryAttempts=3,Delay=TimeSpan.FromSeconds(2),BackoffType=DelayBackoffType.Exponential,UseJitter=true,ShouldHandle=KeyVaultTransientErrors.IsTransient,}).AddTimeout(TimeSpan.FromSeconds(10)));// Inject ResilientSecretClient into your servicespublicclassSecretsService(ResilientSecretClientclient){publicasyncTask<string>GetConnectionStringAsync(CancellationTokenct)=>(awaitclient.GetSecretAsync("db-connection-string",cancellationToken:ct)).Value.Value;}
3. With a URI shortcut (registers SecretClient automatically)
// Use ExecuteAsync<T> for any SecretClient method not covered by typed overloadsvarprops=awaitresilient.ExecuteAsync((c,ct)=>c.GetDeletedSecretAsync("old-secret",ct));
API reference
ResilientSecretClient
Member
Description
Inner
The underlying SecretClient
GetSecretAsync(name, version?, ct)
Retrieves a secret through the pipeline
SetSecretAsync(name, value, ct)
Creates or updates a secret through the pipeline
StartDeleteSecretAsync(name, ct)
Begins deletion through the pipeline
ExecuteAsync<T>(operation, ct)
Runs any SecretClient operation through the pipeline
KeyVaultTransientErrors
Member
Description
IsTransient
PredicateBuilder for 429/503/504 RequestFailedException, HttpRequestException, TaskCanceledException
StatusCodes
IReadOnlySet<int> — {429, 503, 504}
Extension methods
Method
Description
client.WithPolly(pipeline)
Wraps a SecretClient with a pre-built ResiliencePipeline
client.WithPolly(configure)
Builds a pipeline inline and wraps the client
DI extensions
Method
Description
services.AddPollyAzureKeyVault(configure)
Registers ResiliencePipeline + ResilientSecretClient (requires SecretClient already in DI)
services.AddPollyAzureKeyVault(uri, configure)
Registers SecretClient with DefaultAzureCredential, then pipeline + resilient client
ASP.NET Core health checks for Polly v8 circuit breakers — expose circuit-breaker state (Closed, HalfOpen, Open, Isolated) as /health endpoint responses
Polly v8 resilience pipelines for Entity Framework Core — wrap every EF Core query and SaveChanges with retry, timeout and circuit-breaker via a single AddPollyResilience() call
Polly v8 resilience for RabbitMQ.Client v7+ — retry, circuit-breaker, and timeout for IChannel operations, with built-in RabbitMqTransientErrors predicate covering AlreadyClosedException, BrokerUnreachableException, OperationInterruptedException, and ConnectFailureException
Polly v8 resilience pipelines for Npgsql (PostgreSQL) — retry, timeout, and circuit-breaker for NpgsqlConnection queries and commands, plus a built-in PostgresTransientErrors predicate covering all common PostgreSQL transient SQLSTATE codes
Polly v8 resilience pipelines for Elastic.Clients.Elasticsearch 8+ — retry, timeout, and circuit-breaker for any Elasticsearch operation, plus a built-in ElasticTransientErrors predicate covering rate limiting (429), service unavailability (503), gateway timeouts (504), and connection failures
Polly v8 resilience pipelines for Azure Cosmos DB — retry, timeout, and circuit-breaker for Container operations, plus a built-in CosmosTransientErrors predicate covering rate limiting (429), timeouts (408), partition failovers (410), and service unavailability (503)
Polly v8 resilience pipelines for MongoDB.Driver — wrap Find, InsertOne, UpdateOne, DeleteOne and other IMongoCollection calls with retry, timeout, circuit-breaker, and more using a single ResilientMongoCollection decorator
Polly v8 resilience pipelines for Dapper — wrap QueryAsync, ExecuteAsync, and other Dapper calls with retry, timeout, circuit-breaker, and more using a single ResilientDbConnection decorator
Polly v8 resilience pipelines for MediatR — add retry, timeout, circuit-breaker, rate-limiting, hedging, and chaos engineering to any MediatR request handler with a single line of DI registration
Polly v8 resilience pipelines for Microsoft.Data.SqlClient (SQL Server and Azure SQL) — retry, timeout, and circuit-breaker for SqlConnection queries and commands, plus a built-in SqlServerTransientErrors predicate covering all common SQL Server and Azure SQL transient error numbers
Polly v8 resilience pipelines for Azure Blob Storage — wrap BlobClient and BlobContainerClient operations with retry, timeout, circuit-breaker, and more using ResilientBlobClient and ResilientBlobContainerClient decorators