<PackageReference Include="Polly" Version="7.2.2" />

PolicyRegistry

Stores a registry of String and policy pairs.
public int Count { get; }

Total number of policies in the registry.

public IsPolicy this[string key] { get; set; }

Gets of sets the IsPolicy with the specified key. To retrieve a policy directly as a particular Policy type or Policy interface (avoiding a cast), use the Get<T> method.

public PolicyRegistry()

Creates a registry of policies with String keys.

public void Add<TPolicy>(string key, TPolicy policy) where TPolicy : IsPolicy

Adds a policy with the provided key and policy to the registry.

public TPolicy AddOrUpdate<TPolicy>(string key, Func<string, TPolicy> addPolicyFactory, Func<string, TPolicy, TPolicy> updatePolicyFactory) where TPolicy : IsPolicy

Adds a key/policy pair to the registry if the key does not already exist, or updates a key/policy pair in the registry if the key already exists.

public TPolicy AddOrUpdate<TPolicy>(string key, TPolicy addPolicy, Func<string, TPolicy, TPolicy> updatePolicyFactory) where TPolicy : IsPolicy

Adds a key/policy pair to the registry if the key does not already exist, or updates a key/policy pair in the registry if the key already exists.

public void Clear()

Removes all keys and policies from registry.

public bool ContainsKey(string key)

Determines whether the specified key exists.

public TPolicy Get<TPolicy>(string key) where TPolicy : IsPolicy

Gets the policy stored under the provided key, casting to TPolicy.

Returns an enumerator that iterates through the policy objects in the PolicyRegistry.

public TPolicy GetOrAdd<TPolicy>(string key, Func<string, TPolicy> policyFactory) where TPolicy : IsPolicy

Adds a policy with the provided key and policy to the registry if the key does not already exist.

public TPolicy GetOrAdd<TPolicy>(string key, TPolicy policy) where TPolicy : IsPolicy

Adds a key/policy pair to the registry if the key does not already exist.

public bool Remove(string key)

Removes the policy stored under the specified key from the registry.

public bool TryAdd<TPolicy>(string key, TPolicy policy) where TPolicy : IsPolicy

Adds a policy with the provided key and policy to the registry.

public bool TryGet<TPolicy>(string key, out TPolicy policy) where TPolicy : IsPolicy

Gets the policy stored under the provided key, casting to TPolicy.

public bool TryRemove<TPolicy>(string key, out TPolicy policy) where TPolicy : IsPolicy

Removes the policy stored under the specified key from the registry.

public bool TryUpdate<TPolicy>(string key, TPolicy newPolicy, TPolicy comparisonPolicy) where TPolicy : IsPolicy

Compares the existing policy for the specified key with a specified policy, and if they are equal, updates the policy with a third value.