-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add interface providing read-only access to a policy registry (#283)
* Add interface providing read-only access to a policy registry Adds an interface providing read-only access to a policy registry. Useful to prevent consumers changing policies in registry; for example to enforce separation of population of policy registry from usage. * Add IReadOnlyPolicyRegistrySpecs
- Loading branch information
1 parent
5351447
commit f4ee744
Showing
10 changed files
with
333 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Polly; | ||
|
||
namespace Polly.Registry | ||
{ | ||
/// <summary> | ||
/// Represents a read-only collection of policies keyed by <typeparamref name="TKey"/>. | ||
/// </summary> | ||
/// <typeparam name="TKey">The type of keys in the policy registry.</typeparam> | ||
public interface IReadOnlyPolicyRegistry<in TKey> | ||
{ | ||
/// <summary> | ||
/// Gets the <see cref="IsPolicy"/> with the specified key. | ||
/// <remarks>To retrieve a policy directly as a particular Policy type or Policy interface (avoiding a cast), use the <see cref="Get{TPolicy}"/> method.</remarks> | ||
/// </summary> | ||
/// <param name="key">The key of the value to get or set.</param> | ||
/// <exception cref="T:System.ArgumentNullException"><paramref name="key" /> is null.</exception> | ||
/// <exception cref="KeyNotFoundException">The given key was not present in the dictionary.</exception> | ||
/// <returns>The value associated with the specified key.</returns> | ||
IsPolicy this[TKey key] { get; } | ||
|
||
/// <summary> | ||
/// Gets the policy stored under the provided key, casting to <typeparamref name="TPolicy"/>. | ||
/// </summary> | ||
/// <typeparam name="TPolicy">The type of Policy.</typeparam> | ||
/// <returns>The policy stored in the registry under the given key.</returns> | ||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null.</exception> | ||
TPolicy Get<TPolicy>(TKey key) where TPolicy : IsPolicy; | ||
|
||
/// <summary> | ||
/// Gets the policy stored under the provided key, casting to <typeparamref name="TPolicy"/>. | ||
/// </summary> | ||
/// <param name="key">The key of the policy to get.</param> | ||
/// <param name="policy"> | ||
/// This method returns the policy associated with the specified <paramref name="key"/>, if the | ||
/// key is found; otherwise null. | ||
/// This parameter is passed uninitialized. | ||
/// </param> | ||
/// <typeparam name="TPolicy">The type of Policy.</typeparam> | ||
/// <returns>True if Policy exists for the provided Key. False otherwise.</returns> | ||
bool TryGet<TPolicy>(TKey key, out TPolicy policy) where TPolicy : IsPolicy; | ||
|
||
/// <summary> | ||
/// Total number of policies in the registry. | ||
/// </summary> | ||
int Count { get; } | ||
|
||
/// <summary> | ||
/// Determines whether the specified <paramref name="key"/> exists. | ||
/// </summary> | ||
/// <param name="key">The Key to locate in the registry</param> | ||
/// <returns>True if <paramref name="key"/> exists otherwise false</returns> | ||
/// <exception cref="ArgumentNullException"><paramref name="key"/> is null</exception> | ||
bool ContainsKey(TKey key); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.