diff --git a/docs/advanced/dependency-injection.md b/docs/advanced/dependency-injection.md index 518704a1842..bf80a289e07 100644 --- a/docs/advanced/dependency-injection.md +++ b/docs/advanced/dependency-injection.md @@ -251,19 +251,18 @@ ResiliencePipeline instanceB = pipelineProvider.GetPipeline(new MyPipelineKey("m ``` -## Patterns and anti-patterns +## Anti-patterns Over the years, many developers have used Polly in various ways. Some of these -recurring patterns may not be ideal. This section highlights the recommended practices -and those to avoid. +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. -### 1 - Accessing the `IServiceCollection` instead of `IServiceProvider` +### Accessing the `IServiceCollection` instead of `IServiceProvider` ❌ DON'T Capture `IServiceCollection` inside `AddResiliencePipeline()`: - + ```cs var services = new ServiceCollection(); services.AddResiliencePipeline("myFavoriteStrategy", builder => diff --git a/docs/advanced/resilience-context.md b/docs/advanced/resilience-context.md index 2bfc3025306..0fa35e48273 100644 --- a/docs/advanced/resilience-context.md +++ b/docs/advanced/resilience-context.md @@ -1,6 +1,6 @@ # Resilience context -The `ResilienceContext` class in Polly provides an execution-scoped instance that accompanies each execution through a Polly resilience strategy. This class serves to share context and facilitate information exchange between the pre-execution, mid-execution, and post-execution phases. +The `ResilienceContext` class in Polly provides an execution-scoped instance that accompanies each execution through a Polly resilience pipeline and across all strategies in the pipeline. This class serves to share context and facilitate information exchange between the pre-execution, mid-execution, and post-execution phases. The resilience context exposes several properties: diff --git a/docs/strategies/circuit-breaker.md b/docs/strategies/circuit-breaker.md index 8353ba47b7a..ab9a53043d3 100644 --- a/docs/strategies/circuit-breaker.md +++ b/docs/strategies/circuit-breaker.md @@ -306,7 +306,8 @@ sequenceDiagram ## Anti-patterns -Over the years, many developers have used Polly in various ways. Some of these recurring patterns may not be ideal. This section highlights the recommended practices and those to avoid. +Over the years, many developers have used Polly in various ways. Some of these +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. ### Using different sleep duration between retry attempts based on Circuit Breaker state diff --git a/docs/strategies/fallback.md b/docs/strategies/fallback.md index 37340084fad..2732d807e04 100644 --- a/docs/strategies/fallback.md +++ b/docs/strategies/fallback.md @@ -154,7 +154,8 @@ Here's a breakdown of the behavior when the callback produces either an `HttpSta ## Anti-patterns -Over the years, many developers have used Polly in various ways. Some of these recurring patterns may not be ideal. This section highlights the recommended practices and ones to avoid. +Over the years, many developers have used Polly in various ways. Some of these +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. ### Using fallback to replace thrown exception diff --git a/docs/strategies/retry.md b/docs/strategies/retry.md index f15c2363f9e..12e94f1db8e 100644 --- a/docs/strategies/retry.md +++ b/docs/strategies/retry.md @@ -200,7 +200,8 @@ while (!cancellationToken.IsCancellationRequested) ## Anti-patterns -Over the years, many developers have used Polly in various ways. Some of these recurring patterns may not be ideal. This section highlights the recommended practices and those to avoid. +Over the years, many developers have used Polly in various ways. Some of these +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. ### Overusing builder methods diff --git a/docs/strategies/timeout.md b/docs/strategies/timeout.md index 4c5969ab16b..3fa22f9d072 100644 --- a/docs/strategies/timeout.md +++ b/docs/strategies/timeout.md @@ -127,6 +127,9 @@ sequenceDiagram ## Anti-patterns +Over the years, many developers have used Polly in various ways. Some of these +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. + ### Ignoring Cancellation Token ❌ DON'T diff --git a/src/Snippets/Docs/DependencyInjection.cs b/src/Snippets/Docs/DependencyInjection.cs index db362fd8ebe..7947d913cde 100644 --- a/src/Snippets/Docs/DependencyInjection.cs +++ b/src/Snippets/Docs/DependencyInjection.cs @@ -192,7 +192,8 @@ public static async Task ConfigureRegistry(IServiceProvider serviceProvider) public static void AntiPattern_1() { - #region di-anti-pattern-1 + #region di-not-using-service-provider + var services = new ServiceCollection(); services.AddResiliencePipeline("myFavoriteStrategy", builder => { @@ -207,6 +208,7 @@ public static void AntiPattern_1() } }); }); + #endregion }