Table of Contents

Class PollyServiceCollectionExtensions

Namespace
Polly
Assembly
Polly.Extensions.dll

Provides extension methods for registering resilience pipelines using the IServiceCollection.

public static class PollyServiceCollectionExtensions
Inheritance
PollyServiceCollectionExtensions
Inherited Members

Methods

AddResiliencePipelineRegistry<TKey>(IServiceCollection)

Adds ResiliencePipelineRegistry<TKey> and ResiliencePipelineProvider<TKey> to the service collection that allows configuring and retrieving resilience pipelines using the TKey key.

public static IServiceCollection AddResiliencePipelineRegistry<TKey>(this IServiceCollection services) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add the resilience pipeline to.

Returns

IServiceCollection

The updated IServiceCollection with additional services added.

Type Parameters

TKey

The type of the key used to identify the resilience pipeline.

Remarks

This call enables telemetry for all resilience pipelines created using ResiliencePipelineRegistry<TKey>.

Exceptions

ArgumentNullException

Thrown when services is null.

AddResiliencePipelineRegistry<TKey>(IServiceCollection, Action<ResiliencePipelineRegistryOptions<TKey>>)

Adds ResiliencePipelineRegistry<TKey> and ResiliencePipelineProvider<TKey> to the service collection that allows configuring and retrieving resilience pipelines using the TKey key.

public static IServiceCollection AddResiliencePipelineRegistry<TKey>(this IServiceCollection services, Action<ResiliencePipelineRegistryOptions<TKey>> configure) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add the resilience pipeline to.

configure Action<ResiliencePipelineRegistryOptions<TKey>>

The action that configures the ResiliencePipelineRegistryOptions<TKey> that are used by the registry.

Returns

IServiceCollection

The updated IServiceCollection with additional services added.

Type Parameters

TKey

The type of the key used to identify the resilience pipeline.

Remarks

This call enables telemetry for all resilience pipelines created using ResiliencePipelineRegistry<TKey>.

Exceptions

ArgumentNullException

Thrown when services is null.

AddResiliencePipeline<TKey>(IServiceCollection, TKey, Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<TKey>>)

Adds a resilience pipeline to service collection.

public static IServiceCollection AddResiliencePipeline<TKey>(this IServiceCollection services, TKey key, Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<TKey>> configure) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add the resilience pipeline to.

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<TKey>>

An action that configures the resilience pipeline.

Returns

IServiceCollection

The updated IServiceCollection with the registered resilience pipeline.

Type Parameters

TKey

The type of the key used to identify the resilience pipeline.

Remarks

You can retrieve the registered pipeline by resolving the ResiliencePipelineProvider<TKey> class from the dependency injection container.

This call enables telemetry for the registered resilience pipeline.

Exceptions

ArgumentNullException

Thrown when services or configure is null.

AddResiliencePipeline<TKey>(IServiceCollection, TKey, Action<ResiliencePipelineBuilder>)

Adds a resilience pipeline to service collection.

public static IServiceCollection AddResiliencePipeline<TKey>(this IServiceCollection services, TKey key, Action<ResiliencePipelineBuilder> configure) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add the resilience pipeline to.

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder>

An action that configures the resilience pipeline.

Returns

IServiceCollection

The updated IServiceCollection with the registered resilience pipeline.

Type Parameters

TKey

The type of the key used to identify the resilience pipeline.

Remarks

You can retrieve the registered pipeline by resolving the ResiliencePipelineProvider<TKey> class from the dependency injection container.

This call enables telemetry for the registered resilience pipeline.

Exceptions

ArgumentNullException

Thrown when services or configure is null.

AddResiliencePipeline<TKey, TResult>(IServiceCollection, TKey, Action<ResiliencePipelineBuilder<TResult>, AddResiliencePipelineContext<TKey>>)

Adds a resilience pipeline that handles TResult to service collection.

public static IServiceCollection AddResiliencePipeline<TKey, TResult>(this IServiceCollection services, TKey key, Action<ResiliencePipelineBuilder<TResult>, AddResiliencePipelineContext<TKey>> configure) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add the resilience pipeline to.

key TKey

The key used to identify the resilience pipeline.

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

An action that configures the resilience pipeline.

Returns

IServiceCollection

The updated IServiceCollection with the registered resilience pipeline.

Type Parameters

TKey

The type of the key used to identify the resilience pipeline.

TResult

The type of result that the resilience pipeline handles.

Remarks

You can retrieve the registered pipeline by resolving the ResiliencePipelineProvider<TKey> class from the dependency injection container.

This call enables telemetry for the registered resilience pipeline.

Exceptions

ArgumentNullException

Thrown when services or configure is null.

AddResiliencePipeline<TKey, TResult>(IServiceCollection, TKey, Action<ResiliencePipelineBuilder<TResult>>)

Adds a resilience pipeline that handles TResult to service collection.

public static IServiceCollection AddResiliencePipeline<TKey, TResult>(this IServiceCollection services, TKey key, Action<ResiliencePipelineBuilder<TResult>> configure) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add the resilience pipeline to.

key TKey

The key used to identify the resilience pipeline.

configure Action<ResiliencePipelineBuilder<TResult>>

An action that configures the resilience pipeline.

Returns

IServiceCollection

The updated IServiceCollection with the registered resilience pipeline.

Type Parameters

TKey

The type of the key used to identify the resilience pipeline.

TResult

The type of result that the resilience pipeline handles.

Remarks

You can retrieve the registered pipeline by resolving the ResiliencePipelineProvider<TKey> class from the dependency injection container.

This call enables telemetry for the registered resilience pipeline.

Exceptions

ArgumentNullException

Thrown when services or configure is null.

AddResiliencePipelines<TKey>(IServiceCollection, Action<AddResiliencePipelinesContext<TKey>>)

Allows deferred addition of one or more resilience pipelines to the service collection.

public static IServiceCollection AddResiliencePipelines<TKey>(this IServiceCollection services, Action<AddResiliencePipelinesContext<TKey>> configure) where TKey : notnull

Parameters

services IServiceCollection

The IServiceCollection to add resilience pipelines to.

configure Action<AddResiliencePipelinesContext<TKey>>

An action that allows configuration of resilience pipelines.

Returns

IServiceCollection

The updated IServiceCollection with the addition configuration added.

Type Parameters

TKey

The type of the key used to identify the resilience pipelines.

Remarks

This method can be useful if you want to add resilience pipelines as late as possible, e.g. to allow other services / configuration to be available before providing the key.

You can retrieve the registered pipeline by resolving the ResiliencePipelineProvider<TKey> class from the dependency injection container.

This call enables telemetry for the registered resilience pipeline.

Exceptions

ArgumentNullException

Thrown when services or configure is null.