Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] Resilience pipeline registry #1575

Merged
merged 4 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions docs/resilience-pipeline-registry.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,11 @@ The constructor for `ResiliencePipelineRegistry<TKey>` accepts a parameter of ty
| `BuilderFactory` | Function returning a new `ResiliencePipelineBuilder` each time. | Allows consumers to customize builder creation. |
| `PipelineComparer` | `EqualityComparer<TKey>.Default` | Comparer the registry uses to fetch resilience pipelines. |
| `BuilderComparer` | `EqualityComparer<TKey>.Default` | Comparer the registry uses to fetch registered pipeline builders. |
| `InstanceNameFormatter` | `null` | Function formatting `TKey` to instance name. |
| `BuilderNameFormatter` | Function returning the `key.ToString()` value. | Function formatting `TKey` to builder name. |
| `InstanceNameFormatter` | `null` | Delegate formatting `TKey` to instance name. |
| `BuilderNameFormatter` | Function returning the `key.ToString()` value. | Delegate formatting `TKey` to builder name. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
| `BuilderNameFormatter` | Function returning the `key.ToString()` value. | Delegate formatting `TKey` to builder name. |
| `BuilderNameFormatter` | A delegate returning the `key.ToString()` value. | Delegate formatting `TKey` to builder name. |


> [>NOTE]
> The `BuilderName` and `InstanceName` are used in [telemetry](telemetry.md#metrics).

Usage example:

Expand Down Expand Up @@ -152,7 +155,7 @@ The registry caches and manages all pipelines and resources linked to them. When
```cs
var registry = new ResiliencePipelineRegistry<string>();

// This instance is valid event after reload.
// This instance is valid even after reload.
ResiliencePipeline pipeline = registry
.GetOrAddPipeline("A", (builder, context) => builder.AddTimeout(TimeSpan.FromSeconds(10)));

Expand All @@ -170,7 +173,7 @@ catch (ObjectDisposedException)
```
<!-- endSnippet -->

The registry also allows for the registration of dispose callbacks. These are called when a pipeline is discarded, either because of the registry's disposal or after the pipeline is reloaded. The example below works well with dynamic reloads, letting you dispose of the `CancellationTokenSource` when it's not needed anymore.
The registry also allows for the registration of dispose callbacks. These are called when a pipeline is discarded, either because of the registry's disposal or after the pipeline has reloaded. The example below works well with dynamic reloads, letting you dispose of the `CancellationTokenSource` when it's not needed anymore.

<!-- snippet: registry-reloads-and-dispose -->
```cs
Expand All @@ -194,7 +197,7 @@ registry.TryAddBuilder("A", (builder, context) =>
```
<!-- endSnippet -->

Both `AddReloadToken(...)` and `OnPipelineDisposed(...)` are used to implement the `EnableReloads<TOptions>(...)` extension method that is used by the [DI layer](dependency-injection.md#dynamic-reloads).
Both `AddReloadToken(...)` and `OnPipelineDisposed(...)` are used to implement the `EnableReloads<TOptions>(...)` extension method that is used by the [Dependency Injection layer](dependency-injection.md#dynamic-reloads).

## Complex registry keys

Expand Down
2 changes: 0 additions & 2 deletions src/Polly.Core/Registry/ConfigureBuilderContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.ComponentModel;

namespace Polly.Registry;

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions src/Snippets/Docs/ResiliencePipelineRegistry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public static async Task RegistryOptions()
{
BuilderComparer = StringComparer.OrdinalIgnoreCase,
PipelineComparer = StringComparer.OrdinalIgnoreCase,
BuilderFactory = () => new ResiliencePipelineBuilder()
BuilderFactory = () => new ResiliencePipelineBuilder
{
InstanceName = "lets change the defaults",
Name = "lets change the defaults",
Expand Down Expand Up @@ -125,7 +125,7 @@ public static void RegistryDisposed()

var registry = new ResiliencePipelineRegistry<string>();

// This instance is valid event after reload.
// This instance is valid even after reload.
ResiliencePipeline pipeline = registry
.GetOrAddPipeline("A", (builder, context) => builder.AddTimeout(TimeSpan.FromSeconds(10)));

Expand Down Expand Up @@ -171,7 +171,7 @@ public static async Task DynamicReloadsWithDispose()

private static void RegisterCancellationSource(CancellationTokenSource cancellation)
{
// register the source
// Register the source
}
}