Table of Contents

Class ResiliencePipelineRegistry<TKey>

Namespace
Polly.Registry
Assembly
Polly.Core.dll

Represents a registry of resilience pipelines and builders that are accessible by TKey.

public sealed class ResiliencePipelineRegistry<TKey> : ResiliencePipelineProvider<TKey>, IDisposable, IAsyncDisposable where TKey : notnull

Type Parameters

TKey

The type of the key.

Inheritance
ResiliencePipelineRegistry<TKey>
Implements
Inherited Members

Remarks

This class provides a way to organize and manage multiple resilience pipelines using keys of type TKey.

Additionally, it allows registration of callbacks that configure the pipeline using ResiliencePipelineBuilder. These callbacks are called when the resilience pipeline is not yet cached and it's retrieved for the first time.

Constructors

ResiliencePipelineRegistry()

Initializes a new instance of the ResiliencePipelineRegistry<TKey> class with the default comparer.

public ResiliencePipelineRegistry()

ResiliencePipelineRegistry(ResiliencePipelineRegistryOptions<TKey>)

Initializes a new instance of the ResiliencePipelineRegistry<TKey> class with a custom builder factory and comparer.

public ResiliencePipelineRegistry(ResiliencePipelineRegistryOptions<TKey> options)

Parameters

options ResiliencePipelineRegistryOptions<TKey>

The registry options.

Exceptions

ValidationException

Thrown when options are invalid.

ArgumentNullException

Thrown when options are null.

Methods

Dispose()

Disposes all resources that are held by the resilience pipelines created by this builder.

public void Dispose()

Remarks

After the disposal, all resilience pipelines still used outside of the builder are disposed and cannot be used anymore.

DisposeAsync()

Disposes all resources that are held by the resilience pipelines created by this builder.

public ValueTask DisposeAsync()

Returns

ValueTask

Returns a task that represents the asynchronous dispose operation.

Remarks

After the disposal, all resilience pipelines still used outside of the builder are disposed and cannot be used anymore.

GetOrAddPipeline(TKey, Action<ResiliencePipelineBuilder, ConfigureBuilderContext<TKey>>)

Gets existing pipeline or creates a new one using the configure callback.

public ResiliencePipeline GetOrAddPipeline(TKey key, Action<ResiliencePipelineBuilder, ConfigureBuilderContext<TKey>> configure)

Parameters

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder, ConfigureBuilderContext<TKey>>

The callback that configures the pipeline builder.

Returns

ResiliencePipeline

An instance of pipeline.

Exceptions

ObjectDisposedException

Thrown when the registry is already disposed.

GetOrAddPipeline(TKey, Action<ResiliencePipelineBuilder>)

Gets existing pipeline or creates a new one using the configure callback.

public ResiliencePipeline GetOrAddPipeline(TKey key, Action<ResiliencePipelineBuilder> configure)

Parameters

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder>

The callback that configures the pipeline builder.

Returns

ResiliencePipeline

An instance of pipeline.

Exceptions

ObjectDisposedException

Thrown when the registry is already disposed.

GetOrAddPipeline<TResult>(TKey, Action<ResiliencePipelineBuilder<TResult>, ConfigureBuilderContext<TKey>>)

Gets existing pipeline or creates a new one using the configure callback.

public ResiliencePipeline<TResult> GetOrAddPipeline<TResult>(TKey key, Action<ResiliencePipelineBuilder<TResult>, ConfigureBuilderContext<TKey>> configure)

Parameters

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder<TResult>, ConfigureBuilderContext<TKey>>

The callback that configures the pipeline builder.

Returns

ResiliencePipeline<TResult>

An instance of pipeline.

Type Parameters

TResult

The type of result that the resilience pipeline handles.

Exceptions

ObjectDisposedException

Thrown when the registry is already disposed.

GetOrAddPipeline<TResult>(TKey, Action<ResiliencePipelineBuilder<TResult>>)

Gets existing pipeline or creates a new one using the configure callback.

public ResiliencePipeline<TResult> GetOrAddPipeline<TResult>(TKey key, Action<ResiliencePipelineBuilder<TResult>> configure)

Parameters

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder<TResult>>

The callback that configures the pipeline builder.

Returns

ResiliencePipeline<TResult>

An instance of pipeline.

Type Parameters

TResult

The type of result that the resilience pipeline handles.

Exceptions

ObjectDisposedException

Thrown when the registry is already disposed.

TryAddBuilder(TKey, Action<ResiliencePipelineBuilder, ConfigureBuilderContext<TKey>>)

Tries to add a resilience pipeline builder to the registry.

public bool TryAddBuilder(TKey key, Action<ResiliencePipelineBuilder, ConfigureBuilderContext<TKey>> configure)

Parameters

key TKey

The key used to identify the pipeline builder.

configure Action<ResiliencePipelineBuilder, ConfigureBuilderContext<TKey>>

The action that configures the resilience pipeline builder.

Returns

bool

true if the builder was added successfully, false otherwise.

Remarks

Use this method when you want to create the pipeline on-demand when it's first accessed.

Exceptions

ArgumentNullException

Thrown when configure is null.

ObjectDisposedException

Thrown when the registry is already disposed.

TryAddBuilder<TResult>(TKey, Action<ResiliencePipelineBuilder<TResult>, ConfigureBuilderContext<TKey>>)

Tries to add a generic resilience pipeline builder to the registry.

public bool TryAddBuilder<TResult>(TKey key, Action<ResiliencePipelineBuilder<TResult>, ConfigureBuilderContext<TKey>> configure)

Parameters

key TKey

The key used to identify the pipeline builder.

configure Action<ResiliencePipelineBuilder<TResult>, ConfigureBuilderContext<TKey>>

The action that configures the resilience pipeline builder.

Returns

bool

true if the builder was added successfully, false otherwise.

Type Parameters

TResult

The type of result that the resilience pipeline handles.

Remarks

Use this method when you want to create the pipeline on-demand when it's first accessed.

Exceptions

ArgumentNullException

Thrown when configure is null.

ObjectDisposedException

Thrown when the registry is already disposed.

TryGetPipeline(TKey, out ResiliencePipeline?)

Tries to get a resilience pipeline from the provider using the specified key.

public override bool TryGetPipeline(TKey key, out ResiliencePipeline? pipeline)

Parameters

key TKey

The key used to identify the resilience pipeline.

pipeline ResiliencePipeline

The output resilience pipeline if found, null otherwise.

Returns

bool

true if the pipeline was found, false otherwise.

TryGetPipeline<TResult>(TKey, out ResiliencePipeline<TResult>?)

Tries to get a generic resilience pipeline from the provider using the specified key.

public override bool TryGetPipeline<TResult>(TKey key, out ResiliencePipeline<TResult>? pipeline)

Parameters

key TKey

The key used to identify the resilience pipeline.

pipeline ResiliencePipeline<TResult>

The output resilience pipeline if found, null otherwise.

Returns

bool

true if the pipeline was found, false otherwise.

Type Parameters

TResult

The type of result that the resilience pipeline handles.