Polly.Extensions package provides integration with Microsoft.Extensions.DependencyInjection, enabling you to register and manage resilience pipelines through the service collection.
Installation
Core Extension Methods
AddResiliencePipeline
Registers a resilience pipeline with the service collection.IServiceCollection
required
The service collection to add the resilience pipeline to
TKey
required
The key used to identify the resilience pipeline
Action<ResiliencePipelineBuilder>
required
An action that configures the resilience pipeline
IServiceCollection with the registered resilience pipeline.
Example:
AddResiliencePipeline (with context)
Registers a resilience pipeline with access to the service provider and pipeline context.IServiceCollection
required
The service collection to add the resilience pipeline to
TKey
required
The key used to identify the resilience pipeline
Action<ResiliencePipelineBuilder, AddResiliencePipelineContext<TKey>>
required
An action that configures the resilience pipeline with access to context
AddResiliencePipeline<TResult>
Registers a resilience pipeline that handles a specific result type.IServiceCollection
required
The service collection to add the resilience pipeline to
TKey
required
The key used to identify the resilience pipeline
Action<ResiliencePipelineBuilder<TResult>>
required
An action that configures the resilience pipeline for the specific result type
AddResiliencePipelines
Allows deferred addition of one or more resilience pipelines.IServiceCollection
required
The service collection to add resilience pipelines to
Action<AddResiliencePipelinesContext<TKey>>
required
An action that allows configuration of multiple resilience pipelines
AddResiliencePipelineRegistry
RegistersResiliencePipelineRegistry<TKey> and ResiliencePipelineProvider<TKey> to the service collection.
IServiceCollection
required
The service collection to add the registry to
Context Classes
AddResiliencePipelineContext<TKey>
Represents the context for adding a resilience pipeline with the specified key.Properties
Methods
EnableReloads<TOptions> Enables dynamic reloading of the resilience pipeline whenever the specified options are changed.string?
The named options, if any. If null, global options are listened to
string?
The options name, if any. If null, global options are returned
Action
required
The callback delegate to invoke on disposal
AddResiliencePipelinesContext<TKey>
Represents the context for configuring multiple resilience pipelines.Properties
Methods
AddResiliencePipeline Adds a resilience pipeline to the registry.ResiliencePipelineProvider<TKey>
Provides access to resilience pipelines that are registered by key.Methods
GetPipeline Retrieves a resilience pipeline using the specified key.TKey
required
The key used to identify the resilience pipeline
KeyNotFoundException when no resilience pipeline is found for the specified key.
GetPipeline<TResult>
Retrieves a generic resilience pipeline using the specified key.
TKey
required
The key used to identify the resilience pipeline
true if the pipeline was found, false otherwise.