From 472dba855abc46f22077810120291118ce3b6e89 Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Fri, 10 Nov 2023 09:39:47 +0100 Subject: [PATCH 1/3] [Docs] Small cleanup and improvements --- docs/advanced/dependency-injection.md | 7 +++---- docs/advanced/resilience-context.md | 2 +- docs/strategies/circuit-breaker.md | 3 ++- docs/strategies/fallback.md | 3 ++- docs/strategies/retry.md | 3 ++- docs/strategies/timeout.md | 3 +++ 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/advanced/dependency-injection.md b/docs/advanced/dependency-injection.md index 518704a184..d5f4dc3178 100644 --- a/docs/advanced/dependency-injection.md +++ b/docs/advanced/dependency-injection.md @@ -251,13 +251,12 @@ 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 bellow highlights anti-patterns to avoid. -### 1 - Accessing the `IServiceCollection` instead of `IServiceProvider` +### Accessing the `IServiceCollection` instead of `IServiceProvider` ❌ DON'T diff --git a/docs/advanced/resilience-context.md b/docs/advanced/resilience-context.md index 2bfc302530..0fa35e4827 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 8353ba47b7..ce2b62c1c1 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 bellow highlights 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 37340084fa..468a51aed4 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 bellow highlights anti-patterns to avoid. ### Using fallback to replace thrown exception diff --git a/docs/strategies/retry.md b/docs/strategies/retry.md index f15c2363f9..50e00378d4 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 bellow highlights anti-patterns to avoid. ### Overusing builder methods diff --git a/docs/strategies/timeout.md b/docs/strategies/timeout.md index 4c5969ab16..0475f36d87 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 bellow highlights anti-patterns to avoid. + ### Ignoring Cancellation Token ❌ DON'T From bbe3d2326f557280da186fd17a042ea1b039f441 Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Fri, 10 Nov 2023 09:46:50 +0100 Subject: [PATCH 2/3] Cleanup names --- docs/advanced/dependency-injection.md | 2 +- src/Snippets/Docs/DependencyInjection.cs | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/advanced/dependency-injection.md b/docs/advanced/dependency-injection.md index d5f4dc3178..6746ca3c5a 100644 --- a/docs/advanced/dependency-injection.md +++ b/docs/advanced/dependency-injection.md @@ -262,7 +262,7 @@ recurring patterns may not be ideal. The sections bellow highlights anti-pattern Capture `IServiceCollection` inside `AddResiliencePipeline()`: - + ```cs var services = new ServiceCollection(); services.AddResiliencePipeline("myFavoriteStrategy", builder => diff --git a/src/Snippets/Docs/DependencyInjection.cs b/src/Snippets/Docs/DependencyInjection.cs index db362fd8eb..7947d913cd 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 } From a4565bf73c7ac3893ad7c16224b4d1266fe8cf13 Mon Sep 17 00:00:00 2001 From: Martin Tomka Date: Fri, 10 Nov 2023 15:04:31 +0100 Subject: [PATCH 3/3] PR comments --- docs/advanced/dependency-injection.md | 2 +- docs/strategies/circuit-breaker.md | 2 +- docs/strategies/fallback.md | 2 +- docs/strategies/retry.md | 2 +- docs/strategies/timeout.md | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/advanced/dependency-injection.md b/docs/advanced/dependency-injection.md index 6746ca3c5a..bf80a289e0 100644 --- a/docs/advanced/dependency-injection.md +++ b/docs/advanced/dependency-injection.md @@ -254,7 +254,7 @@ ResiliencePipeline instanceB = pipelineProvider.GetPipeline(new MyPipelineKey("m ## Anti-patterns Over the years, many developers have used Polly in various ways. Some of these -recurring patterns may not be ideal. The sections bellow highlights anti-patterns to avoid. +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. ### Accessing the `IServiceCollection` instead of `IServiceProvider` diff --git a/docs/strategies/circuit-breaker.md b/docs/strategies/circuit-breaker.md index ce2b62c1c1..ab9a53043d 100644 --- a/docs/strategies/circuit-breaker.md +++ b/docs/strategies/circuit-breaker.md @@ -307,7 +307,7 @@ 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 bellow highlights anti-patterns to avoid. +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 468a51aed4..2732d807e0 100644 --- a/docs/strategies/fallback.md +++ b/docs/strategies/fallback.md @@ -155,7 +155,7 @@ 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. The sections bellow highlights anti-patterns to avoid. +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 50e00378d4..12e94f1db8 100644 --- a/docs/strategies/retry.md +++ b/docs/strategies/retry.md @@ -201,7 +201,7 @@ 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. The sections bellow highlights anti-patterns to avoid. +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 0475f36d87..3fa22f9d07 100644 --- a/docs/strategies/timeout.md +++ b/docs/strategies/timeout.md @@ -128,7 +128,7 @@ 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 bellow highlights anti-patterns to avoid. +recurring patterns may not be ideal. The sections below highlight anti-patterns to avoid. ### Ignoring Cancellation Token