-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
PolicyRegistry
PolicyRegistry
provides a registry for storing configured policy instances and retrieving them later for use.
PolicyRegistry
promotes separation of policy definition and usage, enabling common patterns such as defining policies centrally on start-up, and passing them to point-of-use by dependency injection.
A PolicyRegistry instance may typically be accessed around the app by dependency injection or the ambient-context pattern.
PolicyRegistry
has Dictionary<string, Policy>
-like semantics.
PolicyRegistry registry = new PolicyRegistry();
registry.Add("StandardHttpResilience", myStandardHttpResiliencePolicy);
// Or:
registry["StandardHttpResilience"] = myStandardHttpResiliencePolicy;
// Pass the registry instance to usage sites by DI, perhaps
public class MyServiceGateway
{
public void MyServiceGateway(..., IPolicyRegistry<string> registry, ...)
{
...
}
}
For those who prefer, a PolicyRegistry
instance could be exposed as a thread-safe singleton, allowing it to be used as an ambient context.
registry.Get<IAsyncPolicy<HttpResponseMessage>>("StandardHttpResilience")
.ExecuteAsync<HttpResponseMessage>(...)
PolicyRegistry
exposes further semantics, with standard dictionary-like behaviour:
.ContainsKey(...)
.TryGet<TPolicy>(...)
.Count
.Clear()
-
Remove(...)
.
The default implementation is in-memory, backed by ConcurrentDictionary
.
The default implementation is (intentionally) agnostic about what the string key
represents, for maximum flexibility. Users may define their own patterns for keys.
Polly also exposes an IPolicyRegistry<in TKey>
interface. You may fulfil this interface with your own implementation. This could be used, for example:
- to provide an implementation backed by an alternative store
- to provide an implementation with a compound
TKey
of some kind.
- Home
- Polly RoadMap
- Contributing
- Transient fault handling and proactive resilience engineering
- Supported targets
- Retry
- Circuit Breaker
- Advanced Circuit Breaker
- Timeout
- Bulkhead
- Cache
- Rate-Limit
- Fallback
- PolicyWrap
- NoOp
- PolicyRegistry
- Polly and HttpClientFactory
- Asynchronous action execution
- Handling InnerExceptions and AggregateExceptions
- Statefulness of policies
- Keys and Context Data
- Non generic and generic policies
- Polly and interfaces
- Some policy patterns
- Debugging with Polly in Visual Studio
- Unit-testing with Polly
- Polly concept and architecture
- Polly v6 breaking changes
- Polly v7 breaking changes
- DISCUSSION PROPOSAL- Polly eventing and metrics architecture