From f8bea0597a6a2b2fbe55030f4f0b283a481c7c08 Mon Sep 17 00:00:00 2001 From: martintmk <103487740+martintmk@users.noreply.github.com> Date: Fri, 28 Jul 2023 10:20:45 +0200 Subject: [PATCH] Rename `ResilienceStrategyBuilder` to `CompositeStrategyBuilder` (#1448) --- .../CreationBenchmark.cs | 2 +- .../TelemetryBenchmark.cs | 4 +- .../Utils/Helper.CircuitBreaker.cs | 2 +- .../Utils/Helper.MultipleStrategies.cs | 2 +- bench/Polly.Core.Benchmarks/Utils/Helper.cs | 4 +- ...akerCompositeStrategyBuilderExtensions.cs} | 12 +-- .../CircuitBreakerStateProvider.cs | 2 +- ...cs => CompositeStrategyBuilder.TResult.cs} | 10 +- ...Builder.cs => CompositeStrategyBuilder.cs} | 4 +- ...ase.cs => CompositeStrategyBuilderBase.cs} | 18 ++-- ... => CompositeStrategyBuilderExtensions.cs} | 12 +-- ...backCompositeStrategyBuilderExtensions.cs} | 10 +- ...gingCompositeStrategyBuilderExtensions.cs} | 12 +-- src/Polly.Core/PublicAPI.Unshipped.txt | 100 +++++++++--------- src/Polly.Core/README.md | 28 ++--- .../ResilienceStrategyRegistry.TResult.cs | 12 +-- .../Registry/ResilienceStrategyRegistry.cs | 24 ++--- .../ResilienceStrategyRegistryOptions.cs | 6 +- ...etryCompositeStrategyBuilderExtensions.cs} | 10 +- ...erContext.cs => StrategyBuilderContext.cs} | 4 +- ...eoutCompositeStrategyBuilderExtensions.cs} | 8 +- ...line.cs => CompositeResilienceStrategy.cs} | 22 ++-- ...esilienceStrategyPipeline.DebuggerProxy.cs | 6 +- .../PollyServiceCollectionExtensions.cs | 16 +-- src/Polly.Extensions/PublicAPI.Unshipped.txt | 14 +-- src/Polly.Extensions/README.md | 2 +- ...etryCompositeStrategyBuilderExtensions.cs} | 12 +-- .../PublicAPI.Unshipped.txt | 10 +- ...iterCompositeStrategyBuilderExtensions.cs} | 12 +-- src/Polly.Testing/README.md | 2 +- .../ResilienceStrategyExtensions.cs | 2 +- ...itBreakerCompositeStrategyBuilderTests.cs} | 24 ++--- ...> CompositeStrategyBuilderContextTests.cs} | 4 +- ...ts.cs => CompositeStrategyBuilderTests.cs} | 52 ++++----- ...ompositeStrategyBuilderExtensionsTests.cs} | 14 +-- ...> GenericCompositeStrategyBuilderTests.cs} | 8 +- ...ompositeStrategyBuilderExtensionsTests.cs} | 6 +- ...uesTests.CircuitBreakerStateSharing_959.cs | 2 +- .../Issues/IssuesTests.FlowingContext_849.cs | 2 +- .../IssuesTests.HandleMultipleResults_898.cs | 2 +- .../ResilienceStrategyRegistryTests.cs | 4 +- .../ResilienceStrategyTests.cs | 4 +- ...ompositeStrategyBuilderExtensionsTests.cs} | 26 ++--- ...ompositeStrategyBuilderExtensionsTests.cs} | 14 +-- ...cs => CompositeResilienceStrategyTests.cs} | 36 +++---- .../PollyServiceCollectionExtensionTests.cs | 20 ++-- ...ompositeStrategyBuilderExtensionsTests.cs} | 4 +- ...ompositeStrategyBuilderExtensionsTests.cs} | 26 ++--- .../RateLimiterResilienceStrategyTests.cs | 2 +- ...lienceStrategyConversionExtensionsTests.cs | 4 +- .../ResilienceStrategyExtensionsTests.cs | 4 +- 51 files changed, 321 insertions(+), 321 deletions(-) rename src/Polly.Core/CircuitBreaker/{CircuitBreakerResilienceStrategyBuilderExtensions.cs => CircuitBreakerCompositeStrategyBuilderExtensions.cs} (87%) rename src/Polly.Core/{ResilienceStrategyBuilder.TResult.cs => CompositeStrategyBuilder.TResult.cs} (71%) rename src/Polly.Core/{ResilienceStrategyBuilder.cs => CompositeStrategyBuilder.cs} (81%) rename src/Polly.Core/{ResilienceStrategyBuilderBase.cs => CompositeStrategyBuilderBase.cs} (88%) rename src/Polly.Core/{ResilienceStrategyBuilderExtensions.cs => CompositeStrategyBuilderExtensions.cs} (87%) rename src/Polly.Core/Fallback/{FallbackResilienceStrategyBuilderExtensions.cs => FallbackCompositeStrategyBuilderExtensions.cs} (85%) rename src/Polly.Core/Hedging/{HedgingResilienceStrategyBuilderExtensions.cs => HedgingCompositeStrategyBuilderExtensions.cs} (84%) rename src/Polly.Core/Retry/{RetryResilienceStrategyBuilderExtensions.cs => RetryCompositeStrategyBuilderExtensions.cs} (83%) rename src/Polly.Core/{ResilienceStrategyBuilderContext.cs => StrategyBuilderContext.cs} (94%) rename src/Polly.Core/Timeout/{TimeoutResilienceStrategyBuilderExtensions.cs => TimeoutCompositeStrategyBuilderExtensions.cs} (90%) rename src/Polly.Core/Utils/{ResilienceStrategyPipeline.cs => CompositeResilienceStrategy.cs} (75%) rename src/Polly.Extensions/Telemetry/{TelemetryResilienceStrategyBuilderExtensions.cs => TelemetryCompositeStrategyBuilderExtensions.cs} (87%) rename src/Polly.RateLimiting/{RateLimiterResilienceStrategyBuilderExtensions.cs => RateLimiterCompositeStrategyBuilderExtensions.cs} (93%) rename test/Polly.Core.Tests/CircuitBreaker/{CircuitBreakerResilienceStrategyBuilderTests.cs => CircuitBreakerCompositeStrategyBuilderTests.cs} (80%) rename test/Polly.Core.Tests/{ResilienceStrategyBuilderContextTests.cs => CompositeStrategyBuilderContextTests.cs} (80%) rename test/Polly.Core.Tests/{ResilienceStrategyBuilderTests.cs => CompositeStrategyBuilderTests.cs} (86%) rename test/Polly.Core.Tests/Fallback/{FallbackResilienceStrategyBuilderExtensionsTests.cs => FallbackCompositeStrategyBuilderExtensionsTests.cs} (76%) rename test/Polly.Core.Tests/{GenericResilienceStrategyBuilderTests.cs => GenericCompositeStrategyBuilderTests.cs} (82%) rename test/Polly.Core.Tests/Hedging/{HedgingResilienceStrategyBuilderExtensionsTests.cs => HedgingCompositeStrategyBuilderExtensionsTests.cs} (94%) rename test/Polly.Core.Tests/Retry/{RetryResilienceStrategyBuilderExtensionsTests.cs => RetryCompositeStrategyBuilderExtensionsTests.cs} (77%) rename test/Polly.Core.Tests/Timeout/{TimeoutResilienceStrategyBuilderExtensionsTests.cs => TimeoutCompositeStrategyBuilderExtensionsTests.cs} (75%) rename test/Polly.Core.Tests/Utils/{ResilienceStrategyPipelineTests.cs => CompositeResilienceStrategyTests.cs} (64%) rename test/Polly.Extensions.Tests/Telemetry/{TelemetryResilienceStrategyBuilderExtensionsTests.cs => TelemetryCompositeStrategyBuilderExtensionsTests.cs} (91%) rename test/Polly.RateLimiting.Tests/{RateLimiterResilienceStrategyBuilderExtensionsTests.cs => RateLimiterCompositeStrategyBuilderExtensionsTests.cs} (79%) diff --git a/bench/Polly.Core.Benchmarks/CreationBenchmark.cs b/bench/Polly.Core.Benchmarks/CreationBenchmark.cs index f6100970ff5..818a0091537 100644 --- a/bench/Polly.Core.Benchmarks/CreationBenchmark.cs +++ b/bench/Polly.Core.Benchmarks/CreationBenchmark.cs @@ -15,7 +15,7 @@ public static void Fallback_V7() [Benchmark] public static void Fallback_V8() { - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .AddFallback(new() { FallbackAction = _ => Outcome.FromResultAsTask("fallback") diff --git a/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs b/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs index cdd7ff0555f..ed04e2a6765 100644 --- a/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs +++ b/bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs @@ -13,7 +13,7 @@ public class TelemetryBenchmark [GlobalSetup] public void Prepare() { - _strategy = Build(new ResilienceStrategyBuilder()); + _strategy = Build(new CompositeStrategyBuilder()); if (Telemetry) { @@ -38,7 +38,7 @@ public async ValueTask Execute() ResilienceContextPool.Shared.Return(context); } - private ResilienceStrategy Build(ResilienceStrategyBuilder builder) + private ResilienceStrategy Build(CompositeStrategyBuilder builder) { builder.AddStrategy(context => new TelemetryEventStrategy(context.Telemetry), new EmptyResilienceOptions()); diff --git a/bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs b/bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs index 411aa8b48db..43af5ba582b 100644 --- a/bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs +++ b/bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs @@ -13,7 +13,7 @@ public static object CreateOpenedCircuitBreaker(PollyVersion version, bool handl if (version == PollyVersion.V8) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); if (handleOutcome) { diff --git a/bench/Polly.Core.Benchmarks/Utils/Helper.MultipleStrategies.cs b/bench/Polly.Core.Benchmarks/Utils/Helper.MultipleStrategies.cs index 404f6f2e178..1ce8c58c827 100644 --- a/bench/Polly.Core.Benchmarks/Utils/Helper.MultipleStrategies.cs +++ b/bench/Polly.Core.Benchmarks/Utils/Helper.MultipleStrategies.cs @@ -59,7 +59,7 @@ internal static partial class Helper public static ResilienceStrategy CreateNonGenericStrategyPipeline() { - return new ResilienceStrategyBuilder() + return new CompositeStrategyBuilder() .AddConcurrencyLimiter(new ConcurrencyLimiterOptions { QueueLimit = 10, diff --git a/bench/Polly.Core.Benchmarks/Utils/Helper.cs b/bench/Polly.Core.Benchmarks/Utils/Helper.cs index e1876c4b449..1afa00f3861 100644 --- a/bench/Polly.Core.Benchmarks/Utils/Helper.cs +++ b/bench/Polly.Core.Benchmarks/Utils/Helper.cs @@ -26,9 +26,9 @@ public static async ValueTask ExecuteAsync(this object obj, PollyVersion version throw new NotSupportedException(); } - private static ResilienceStrategy CreateStrategy(Action> configure) + private static ResilienceStrategy CreateStrategy(Action> configure) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); configure(builder); return builder.Build(); } diff --git a/src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategyBuilderExtensions.cs b/src/Polly.Core/CircuitBreaker/CircuitBreakerCompositeStrategyBuilderExtensions.cs similarity index 87% rename from src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategyBuilderExtensions.cs rename to src/Polly.Core/CircuitBreaker/CircuitBreakerCompositeStrategyBuilderExtensions.cs index 3c20a9f2288..a7f02bcac3c 100644 --- a/src/Polly.Core/CircuitBreaker/CircuitBreakerResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Core/CircuitBreaker/CircuitBreakerCompositeStrategyBuilderExtensions.cs @@ -6,9 +6,9 @@ namespace Polly; /// -/// Circuit breaker strategy extensions for . +/// Circuit breaker strategy extensions for . /// -public static class CircuitBreakerResilienceStrategyBuilderExtensions +public static class CircuitBreakerCompositeStrategyBuilderExtensions { /// /// Add circuit breaker strategy to the builder. @@ -24,7 +24,7 @@ public static class CircuitBreakerResilienceStrategyBuilderExtensions /// /// Thrown when or is . /// Thrown when are invalid. - public static ResilienceStrategyBuilder AddCircuitBreaker(this ResilienceStrategyBuilder builder, CircuitBreakerStrategyOptions options) + public static CompositeStrategyBuilder AddCircuitBreaker(this CompositeStrategyBuilder builder, CircuitBreakerStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -47,7 +47,7 @@ public static ResilienceStrategyBuilder AddCircuitBreaker(this ResilienceStrateg /// /// Thrown when or is . /// Thrown when are invalid. - public static ResilienceStrategyBuilder AddCircuitBreaker(this ResilienceStrategyBuilder builder, CircuitBreakerStrategyOptions options) + public static CompositeStrategyBuilder AddCircuitBreaker(this CompositeStrategyBuilder builder, CircuitBreakerStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -60,7 +60,7 @@ public static ResilienceStrategyBuilder AddCircuitBreaker(this "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "All options members preserved.")] private static TBuilder AddCircuitBreakerCore(this TBuilder builder, CircuitBreakerStrategyOptions options) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { return builder.AddStrategy( context => @@ -76,7 +76,7 @@ private static TBuilder AddCircuitBreakerCore(this TBuilder b } internal static CircuitBreakerResilienceStrategy CreateStrategy( - ResilienceStrategyBuilderContext context, + StrategyBuilderContext context, CircuitBreakerStrategyOptions options, CircuitBehavior behavior) { diff --git a/src/Polly.Core/CircuitBreaker/CircuitBreakerStateProvider.cs b/src/Polly.Core/CircuitBreaker/CircuitBreakerStateProvider.cs index 36782577adb..4ac17fbd4b3 100644 --- a/src/Polly.Core/CircuitBreaker/CircuitBreakerStateProvider.cs +++ b/src/Polly.Core/CircuitBreaker/CircuitBreakerStateProvider.cs @@ -24,7 +24,7 @@ internal void Initialize(Func circuitStateProvider, Func /// /// The initialization happens when the circuit-breaker strategy is attached to this class. - /// This happens when the final strategy is created by the call. + /// This happens when the final strategy is created by the call. /// internal bool IsInitialized => _circuitStateProvider != null; diff --git a/src/Polly.Core/ResilienceStrategyBuilder.TResult.cs b/src/Polly.Core/CompositeStrategyBuilder.TResult.cs similarity index 71% rename from src/Polly.Core/ResilienceStrategyBuilder.TResult.cs rename to src/Polly.Core/CompositeStrategyBuilder.TResult.cs index ad35560ef84..dba2ef3763f 100644 --- a/src/Polly.Core/ResilienceStrategyBuilder.TResult.cs +++ b/src/Polly.Core/CompositeStrategyBuilder.TResult.cs @@ -7,20 +7,20 @@ namespace Polly; /// /// The type of result to handle. /// -/// The builder supports chaining multiple strategies into a pipeline of strategies. +/// The builder supports combining multiple strategies into a composite resilience strategy. /// The resulting instance of created by the call will execute the strategies in the same order they were added to the builder. /// The order of the strategies is important. /// -public sealed class ResilienceStrategyBuilder : ResilienceStrategyBuilderBase +public sealed class CompositeStrategyBuilder : CompositeStrategyBuilderBase { /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// - public ResilienceStrategyBuilder() + public CompositeStrategyBuilder() { } - internal ResilienceStrategyBuilder(ResilienceStrategyBuilderBase other) + internal CompositeStrategyBuilder(CompositeStrategyBuilderBase other) : base(other) { } diff --git a/src/Polly.Core/ResilienceStrategyBuilder.cs b/src/Polly.Core/CompositeStrategyBuilder.cs similarity index 81% rename from src/Polly.Core/ResilienceStrategyBuilder.cs rename to src/Polly.Core/CompositeStrategyBuilder.cs index e0007454e82..b7d394849f0 100644 --- a/src/Polly.Core/ResilienceStrategyBuilder.cs +++ b/src/Polly.Core/CompositeStrategyBuilder.cs @@ -6,11 +6,11 @@ namespace Polly; /// A builder that is used to create an instance of . /// /// -/// The builder supports chaining multiple strategies into a pipeline of strategies. +/// The builder supports combining multiple strategies into a composite resilience strategy. /// The resulting instance of created by the call will execute the strategies in the same order they were added to the builder. /// The order of the strategies is important. /// -public sealed class ResilienceStrategyBuilder : ResilienceStrategyBuilderBase +public sealed class CompositeStrategyBuilder : CompositeStrategyBuilderBase { /// /// Builds the resilience strategy. diff --git a/src/Polly.Core/ResilienceStrategyBuilderBase.cs b/src/Polly.Core/CompositeStrategyBuilderBase.cs similarity index 88% rename from src/Polly.Core/ResilienceStrategyBuilderBase.cs rename to src/Polly.Core/CompositeStrategyBuilderBase.cs index a2f46aca115..768ff29a062 100644 --- a/src/Polly.Core/ResilienceStrategyBuilderBase.cs +++ b/src/Polly.Core/CompositeStrategyBuilderBase.cs @@ -9,20 +9,20 @@ namespace Polly; /// A builder that is used to create an instance of . /// /// -/// The builder supports chaining multiple strategies into a pipeline of strategies. +/// The builder supports combining multiple strategies into a composite resilience strategy. /// The resulting instance of executes the strategies in the same order they were added to the builder. /// The order of the strategies is important. /// -public abstract class ResilienceStrategyBuilderBase +public abstract class CompositeStrategyBuilderBase { private readonly List _entries = new(); private bool _used; - private protected ResilienceStrategyBuilderBase() + private protected CompositeStrategyBuilderBase() { } - private protected ResilienceStrategyBuilderBase(ResilienceStrategyBuilderBase other) + private protected CompositeStrategyBuilderBase(CompositeStrategyBuilderBase other) { Name = other.Name; Properties = other.Properties; @@ -121,7 +121,7 @@ private protected ResilienceStrategyBuilderBase(ResilienceStrategyBuilderBase ot public Action Validator { get; private protected set; } = ValidationHelper.ValidateObject; [RequiresUnreferencedCode(Constants.OptionsValidation)] - internal void AddStrategyCore(Func factory, ResilienceStrategyOptions options) + internal void AddStrategyCore(Func factory, ResilienceStrategyOptions options) { Guard.NotNull(factory); Guard.NotNull(options); @@ -138,7 +138,7 @@ internal void AddStrategyCore(Func Factory, ResilienceStrategyOptions Options); + private sealed record Entry(Func Factory, ResilienceStrategyOptions Options); } diff --git a/src/Polly.Core/ResilienceStrategyBuilderExtensions.cs b/src/Polly.Core/CompositeStrategyBuilderExtensions.cs similarity index 87% rename from src/Polly.Core/ResilienceStrategyBuilderExtensions.cs rename to src/Polly.Core/CompositeStrategyBuilderExtensions.cs index 251c4badffc..0986ae01bda 100644 --- a/src/Polly.Core/ResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Core/CompositeStrategyBuilderExtensions.cs @@ -4,9 +4,9 @@ namespace Polly; /// -/// Extensions for . +/// Extensions for . /// -public static class ResilienceStrategyBuilderExtensions +public static class CompositeStrategyBuilderExtensions { /// /// Adds an already created strategy instance to the builder. @@ -22,7 +22,7 @@ public static class ResilienceStrategyBuilderExtensions "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "The EmptyOptions have nothing to validate.")] public static TBuilder AddStrategy(this TBuilder builder, ResilienceStrategy strategy) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(strategy); @@ -39,7 +39,7 @@ public static TBuilder AddStrategy(this TBuilder builder, ResilienceSt /// The same builder instance. /// Thrown when is null. /// Thrown when this builder was already used to create a strategy. The builder cannot be modified after it has been used. - public static ResilienceStrategyBuilder AddStrategy(this ResilienceStrategyBuilder builder, ResilienceStrategy strategy) + public static CompositeStrategyBuilder AddStrategy(this CompositeStrategyBuilder builder, ResilienceStrategy strategy) { Guard.NotNull(builder); Guard.NotNull(strategy); @@ -59,8 +59,8 @@ public static ResilienceStrategyBuilder AddStrategy(this Resil /// Thrown when this builder was already used to create a strategy. The builder cannot be modified after it has been used. /// Thrown when is invalid. [RequiresUnreferencedCode(Constants.OptionsValidation)] - public static TBuilder AddStrategy(this TBuilder builder, Func factory, ResilienceStrategyOptions options) - where TBuilder : ResilienceStrategyBuilderBase + public static TBuilder AddStrategy(this TBuilder builder, Func factory, ResilienceStrategyOptions options) + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(factory); diff --git a/src/Polly.Core/Fallback/FallbackResilienceStrategyBuilderExtensions.cs b/src/Polly.Core/Fallback/FallbackCompositeStrategyBuilderExtensions.cs similarity index 85% rename from src/Polly.Core/Fallback/FallbackResilienceStrategyBuilderExtensions.cs rename to src/Polly.Core/Fallback/FallbackCompositeStrategyBuilderExtensions.cs index 7a174fcca46..93f6dec04be 100644 --- a/src/Polly.Core/Fallback/FallbackResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Core/Fallback/FallbackCompositeStrategyBuilderExtensions.cs @@ -5,9 +5,9 @@ namespace Polly; /// -/// Provides extension methods for configuring fallback resilience strategies for . +/// Provides extension methods for configuring fallback resilience strategies for . /// -public static class FallbackResilienceStrategyBuilderExtensions +public static class FallbackCompositeStrategyBuilderExtensions { /// /// Adds a fallback resilience strategy with the provided options to the builder. @@ -18,7 +18,7 @@ public static class FallbackResilienceStrategyBuilderExtensions /// The builder instance with the fallback strategy added. /// Thrown when or is . /// Thrown when are invalid. - public static ResilienceStrategyBuilder AddFallback(this ResilienceStrategyBuilder builder, FallbackStrategyOptions options) + public static CompositeStrategyBuilder AddFallback(this CompositeStrategyBuilder builder, FallbackStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -35,7 +35,7 @@ public static ResilienceStrategyBuilder AddFallback(this Resil /// The builder instance with the fallback strategy added. /// Thrown when or is . /// Thrown when are invalid. - internal static ResilienceStrategyBuilder AddFallback(this ResilienceStrategyBuilder builder, FallbackStrategyOptions options) + internal static CompositeStrategyBuilder AddFallback(this CompositeStrategyBuilder builder, FallbackStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -49,7 +49,7 @@ internal static ResilienceStrategyBuilder AddFallback(this ResilienceStrategyBui "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "All options members preserved.")] internal static void AddFallbackCore( - this ResilienceStrategyBuilderBase builder, + this CompositeStrategyBuilderBase builder, FallbackStrategyOptions options) { builder.AddStrategy(context => diff --git a/src/Polly.Core/Hedging/HedgingResilienceStrategyBuilderExtensions.cs b/src/Polly.Core/Hedging/HedgingCompositeStrategyBuilderExtensions.cs similarity index 84% rename from src/Polly.Core/Hedging/HedgingResilienceStrategyBuilderExtensions.cs rename to src/Polly.Core/Hedging/HedgingCompositeStrategyBuilderExtensions.cs index 632258557e3..63a06f674e9 100644 --- a/src/Polly.Core/Hedging/HedgingResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Core/Hedging/HedgingCompositeStrategyBuilderExtensions.cs @@ -6,9 +6,9 @@ namespace Polly; /// -/// Provides extension methods for configuring hedging resilience strategies for . +/// Provides extension methods for configuring hedging resilience strategies for . /// -public static class HedgingResilienceStrategyBuilderExtensions +public static class HedgingCompositeStrategyBuilderExtensions { /// /// Adds a hedging resilience strategy with the provided options to the builder. @@ -19,7 +19,7 @@ public static class HedgingResilienceStrategyBuilderExtensions /// The builder instance with the hedging strategy added. /// Thrown when or is . /// Thrown when are invalid. - public static ResilienceStrategyBuilder AddHedging(this ResilienceStrategyBuilder builder, HedgingStrategyOptions options) + public static CompositeStrategyBuilder AddHedging(this CompositeStrategyBuilder builder, HedgingStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -36,7 +36,7 @@ public static ResilienceStrategyBuilder AddHedging(this Resili /// The builder instance with the hedging strategy added. /// Thrown when or is . /// Thrown when are invalid. - internal static ResilienceStrategyBuilder AddHedging(this ResilienceStrategyBuilder builder, HedgingStrategyOptions options) + internal static CompositeStrategyBuilder AddHedging(this CompositeStrategyBuilder builder, HedgingStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -50,7 +50,7 @@ internal static ResilienceStrategyBuilder AddHedging(this ResilienceStrategyBuil "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "All options members preserved.")] internal static void AddHedgingCore( - this ResilienceStrategyBuilderBase builder, + this CompositeStrategyBuilderBase builder, HedgingStrategyOptions options) { builder.AddStrategy(context => @@ -58,7 +58,7 @@ internal static ResilienceStrategyBuilder AddHedging(this ResilienceStrategyBuil var handler = new HedgingHandler( options.ShouldHandle!, options.HedgingActionGenerator, - IsGeneric: builder is not ResilienceStrategyBuilder); + IsGeneric: builder is not CompositeStrategyBuilder); return new HedgingResilienceStrategy( options.HedgingDelay, diff --git a/src/Polly.Core/PublicAPI.Unshipped.txt b/src/Polly.Core/PublicAPI.Unshipped.txt index e7aac574c76..301559bd107 100644 --- a/src/Polly.Core/PublicAPI.Unshipped.txt +++ b/src/Polly.Core/PublicAPI.Unshipped.txt @@ -73,7 +73,27 @@ Polly.CircuitBreaker.OnCircuitOpenedArguments Polly.CircuitBreaker.OnCircuitOpenedArguments.BreakDuration.get -> System.TimeSpan Polly.CircuitBreaker.OnCircuitOpenedArguments.IsManual.get -> bool Polly.CircuitBreaker.OnCircuitOpenedArguments.OnCircuitOpenedArguments(System.TimeSpan breakDuration, bool isManual) -> void -Polly.CircuitBreakerResilienceStrategyBuilderExtensions +Polly.CircuitBreakerCompositeStrategyBuilderExtensions +Polly.CompositeStrategyBuilder +Polly.CompositeStrategyBuilder.Build() -> Polly.ResilienceStrategy! +Polly.CompositeStrategyBuilder.CompositeStrategyBuilder() -> void +Polly.CompositeStrategyBuilder +Polly.CompositeStrategyBuilder.Build() -> Polly.ResilienceStrategy! +Polly.CompositeStrategyBuilder.CompositeStrategyBuilder() -> void +Polly.CompositeStrategyBuilderBase +Polly.CompositeStrategyBuilderBase.DiagnosticSource.get -> System.Diagnostics.DiagnosticSource? +Polly.CompositeStrategyBuilderBase.DiagnosticSource.set -> void +Polly.CompositeStrategyBuilderBase.InstanceName.get -> string? +Polly.CompositeStrategyBuilderBase.InstanceName.set -> void +Polly.CompositeStrategyBuilderBase.Name.get -> string? +Polly.CompositeStrategyBuilderBase.Name.set -> void +Polly.CompositeStrategyBuilderBase.OnCreatingStrategy.get -> System.Action!>? +Polly.CompositeStrategyBuilderBase.OnCreatingStrategy.set -> void +Polly.CompositeStrategyBuilderBase.Properties.get -> Polly.ResilienceProperties! +Polly.CompositeStrategyBuilderBase.Randomizer.get -> System.Func! +Polly.CompositeStrategyBuilderBase.Randomizer.set -> void +Polly.CompositeStrategyBuilderBase.Validator.get -> System.Action! +Polly.CompositeStrategyBuilderExtensions Polly.ExecutionRejectedException Polly.ExecutionRejectedException.ExecutionRejectedException() -> void Polly.ExecutionRejectedException.ExecutionRejectedException(string! message) -> void @@ -90,7 +110,7 @@ Polly.Fallback.FallbackStrategyOptions.ShouldHandle.get -> System.Func< Polly.Fallback.FallbackStrategyOptions.ShouldHandle.set -> void Polly.Fallback.OnFallbackArguments Polly.Fallback.OnFallbackArguments.OnFallbackArguments() -> void -Polly.FallbackResilienceStrategyBuilderExtensions +Polly.FallbackCompositeStrategyBuilderExtensions Polly.Hedging.HedgingActionGeneratorArguments Polly.Hedging.HedgingActionGeneratorArguments.ActionContext.get -> Polly.ResilienceContext! Polly.Hedging.HedgingActionGeneratorArguments.AttemptNumber.get -> int @@ -124,7 +144,7 @@ Polly.Hedging.OnHedgingArguments.AttemptNumber.get -> int Polly.Hedging.OnHedgingArguments.ExecutionTime.get -> System.TimeSpan Polly.Hedging.OnHedgingArguments.HasOutcome.get -> bool Polly.Hedging.OnHedgingArguments.OnHedgingArguments(int attemptNumber, bool hasOutcome, System.TimeSpan executionTime) -> void -Polly.HedgingResilienceStrategyBuilderExtensions +Polly.HedgingCompositeStrategyBuilderExtensions Polly.NullResilienceStrategy Polly.NullResilienceStrategy Polly.Outcome @@ -167,24 +187,24 @@ Polly.Registry.ResilienceStrategyProvider.ResilienceStrategyProvider() -> Polly.Registry.ResilienceStrategyRegistry Polly.Registry.ResilienceStrategyRegistry.ClearStrategies() -> void Polly.Registry.ResilienceStrategyRegistry.ClearStrategies() -> void -Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action!>! configure) -> Polly.ResilienceStrategy! -Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action! configure) -> Polly.ResilienceStrategy! -Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action!, Polly.Registry.ConfigureBuilderContext!>! configure) -> Polly.ResilienceStrategy! -Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action!>! configure) -> Polly.ResilienceStrategy! +Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action!>! configure) -> Polly.ResilienceStrategy! +Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action! configure) -> Polly.ResilienceStrategy! +Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action!, Polly.Registry.ConfigureBuilderContext!>! configure) -> Polly.ResilienceStrategy! +Polly.Registry.ResilienceStrategyRegistry.GetOrAddStrategy(TKey key, System.Action!>! configure) -> Polly.ResilienceStrategy! Polly.Registry.ResilienceStrategyRegistry.RemoveBuilder(TKey key) -> bool Polly.Registry.ResilienceStrategyRegistry.RemoveBuilder(TKey key) -> bool Polly.Registry.ResilienceStrategyRegistry.RemoveStrategy(TKey key) -> bool Polly.Registry.ResilienceStrategyRegistry.RemoveStrategy(TKey key) -> bool Polly.Registry.ResilienceStrategyRegistry.ResilienceStrategyRegistry() -> void Polly.Registry.ResilienceStrategyRegistry.ResilienceStrategyRegistry(Polly.Registry.ResilienceStrategyRegistryOptions! options) -> void -Polly.Registry.ResilienceStrategyRegistry.TryAddBuilder(TKey key, System.Action!>! configure) -> bool -Polly.Registry.ResilienceStrategyRegistry.TryAddBuilder(TKey key, System.Action!, Polly.Registry.ConfigureBuilderContext!>! configure) -> bool +Polly.Registry.ResilienceStrategyRegistry.TryAddBuilder(TKey key, System.Action!>! configure) -> bool +Polly.Registry.ResilienceStrategyRegistry.TryAddBuilder(TKey key, System.Action!, Polly.Registry.ConfigureBuilderContext!>! configure) -> bool Polly.Registry.ResilienceStrategyRegistry.TryAddStrategy(TKey key, Polly.ResilienceStrategy! strategy) -> bool Polly.Registry.ResilienceStrategyRegistry.TryAddStrategy(TKey key, Polly.ResilienceStrategy! strategy) -> bool Polly.Registry.ResilienceStrategyRegistryOptions Polly.Registry.ResilienceStrategyRegistryOptions.BuilderComparer.get -> System.Collections.Generic.IEqualityComparer! Polly.Registry.ResilienceStrategyRegistryOptions.BuilderComparer.set -> void -Polly.Registry.ResilienceStrategyRegistryOptions.BuilderFactory.get -> System.Func! +Polly.Registry.ResilienceStrategyRegistryOptions.BuilderFactory.get -> System.Func! Polly.Registry.ResilienceStrategyRegistryOptions.BuilderFactory.set -> void Polly.Registry.ResilienceStrategyRegistryOptions.BuilderNameFormatter.get -> System.Func! Polly.Registry.ResilienceStrategyRegistryOptions.BuilderNameFormatter.set -> void @@ -251,32 +271,6 @@ Polly.ResilienceStrategy.ExecuteAsync(System.Func.ExecuteAsync(System.Func>! callback, Polly.ResilienceContext! context) -> System.Threading.Tasks.ValueTask Polly.ResilienceStrategy.ExecuteAsync(System.Func>! callback, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.ValueTask Polly.ResilienceStrategy.ExecuteOutcomeAsync(System.Func>>! callback, Polly.ResilienceContext! context, TState state) -> System.Threading.Tasks.ValueTask> -Polly.ResilienceStrategyBuilder -Polly.ResilienceStrategyBuilder.Build() -> Polly.ResilienceStrategy! -Polly.ResilienceStrategyBuilder.ResilienceStrategyBuilder() -> void -Polly.ResilienceStrategyBuilder -Polly.ResilienceStrategyBuilder.Build() -> Polly.ResilienceStrategy! -Polly.ResilienceStrategyBuilder.ResilienceStrategyBuilder() -> void -Polly.ResilienceStrategyBuilderBase -Polly.ResilienceStrategyBuilderBase.DiagnosticSource.get -> System.Diagnostics.DiagnosticSource? -Polly.ResilienceStrategyBuilderBase.DiagnosticSource.set -> void -Polly.ResilienceStrategyBuilderBase.InstanceName.get -> string? -Polly.ResilienceStrategyBuilderBase.InstanceName.set -> void -Polly.ResilienceStrategyBuilderBase.Name.get -> string? -Polly.ResilienceStrategyBuilderBase.Name.set -> void -Polly.ResilienceStrategyBuilderBase.OnCreatingStrategy.get -> System.Action!>? -Polly.ResilienceStrategyBuilderBase.OnCreatingStrategy.set -> void -Polly.ResilienceStrategyBuilderBase.Properties.get -> Polly.ResilienceProperties! -Polly.ResilienceStrategyBuilderBase.Randomizer.get -> System.Func! -Polly.ResilienceStrategyBuilderBase.Randomizer.set -> void -Polly.ResilienceStrategyBuilderBase.Validator.get -> System.Action! -Polly.ResilienceStrategyBuilderContext -Polly.ResilienceStrategyBuilderContext.BuilderInstanceName.get -> string? -Polly.ResilienceStrategyBuilderContext.BuilderName.get -> string? -Polly.ResilienceStrategyBuilderContext.BuilderProperties.get -> Polly.ResilienceProperties! -Polly.ResilienceStrategyBuilderContext.StrategyName.get -> string? -Polly.ResilienceStrategyBuilderContext.Telemetry.get -> Polly.Telemetry.ResilienceStrategyTelemetry! -Polly.ResilienceStrategyBuilderExtensions Polly.ResilienceStrategyOptions Polly.ResilienceStrategyOptions.Name.get -> string? Polly.ResilienceStrategyOptions.Name.set -> void @@ -292,8 +286,8 @@ Polly.Retry.OnRetryArguments.OnRetryArguments(int attemptNumber, System.TimeSpan Polly.Retry.OnRetryArguments.RetryDelay.get -> System.TimeSpan Polly.Retry.RetryBackoffType Polly.Retry.RetryBackoffType.Constant = 0 -> Polly.Retry.RetryBackoffType -Polly.Retry.RetryBackoffType.Linear = 1 -> Polly.Retry.RetryBackoffType Polly.Retry.RetryBackoffType.Exponential = 2 -> Polly.Retry.RetryBackoffType +Polly.Retry.RetryBackoffType.Linear = 1 -> Polly.Retry.RetryBackoffType Polly.Retry.RetryDelayArguments Polly.Retry.RetryDelayArguments.AttemptNumber.get -> int Polly.Retry.RetryDelayArguments.DelayHint.get -> System.TimeSpan @@ -321,7 +315,13 @@ Polly.Retry.RetryStrategyOptions.ShouldHandle.get -> System.Func.ShouldHandle.set -> void Polly.Retry.RetryStrategyOptions.UseJitter.get -> bool Polly.Retry.RetryStrategyOptions.UseJitter.set -> void -Polly.RetryResilienceStrategyBuilderExtensions +Polly.RetryCompositeStrategyBuilderExtensions +Polly.StrategyBuilderContext +Polly.StrategyBuilderContext.BuilderInstanceName.get -> string? +Polly.StrategyBuilderContext.BuilderName.get -> string? +Polly.StrategyBuilderContext.BuilderProperties.get -> Polly.ResilienceProperties! +Polly.StrategyBuilderContext.StrategyName.get -> string? +Polly.StrategyBuilderContext.Telemetry.get -> Polly.Telemetry.ResilienceStrategyTelemetry! Polly.Telemetry.ExecutionAttemptArguments Polly.Telemetry.ExecutionAttemptArguments.AttemptNumber.get -> int Polly.Telemetry.ExecutionAttemptArguments.ExecutionAttemptArguments(int attemptNumber, System.TimeSpan executionTime, bool handled) -> void @@ -380,12 +380,15 @@ Polly.Timeout.TimeoutStrategyOptions.Timeout.set -> void Polly.Timeout.TimeoutStrategyOptions.TimeoutGenerator.get -> System.Func>? Polly.Timeout.TimeoutStrategyOptions.TimeoutGenerator.set -> void Polly.Timeout.TimeoutStrategyOptions.TimeoutStrategyOptions() -> void -Polly.TimeoutResilienceStrategyBuilderExtensions +Polly.TimeoutCompositeStrategyBuilderExtensions Polly.Utils.LegacySupport -static Polly.CircuitBreakerResilienceStrategyBuilderExtensions.AddCircuitBreaker(this Polly.ResilienceStrategyBuilder! builder, Polly.CircuitBreaker.CircuitBreakerStrategyOptions! options) -> Polly.ResilienceStrategyBuilder! -static Polly.CircuitBreakerResilienceStrategyBuilderExtensions.AddCircuitBreaker(this Polly.ResilienceStrategyBuilder! builder, Polly.CircuitBreaker.CircuitBreakerStrategyOptions! options) -> Polly.ResilienceStrategyBuilder! -static Polly.FallbackResilienceStrategyBuilderExtensions.AddFallback(this Polly.ResilienceStrategyBuilder! builder, Polly.Fallback.FallbackStrategyOptions! options) -> Polly.ResilienceStrategyBuilder! -static Polly.HedgingResilienceStrategyBuilderExtensions.AddHedging(this Polly.ResilienceStrategyBuilder! builder, Polly.Hedging.HedgingStrategyOptions! options) -> Polly.ResilienceStrategyBuilder! +static Polly.CircuitBreakerCompositeStrategyBuilderExtensions.AddCircuitBreaker(this Polly.CompositeStrategyBuilder! builder, Polly.CircuitBreaker.CircuitBreakerStrategyOptions! options) -> Polly.CompositeStrategyBuilder! +static Polly.CircuitBreakerCompositeStrategyBuilderExtensions.AddCircuitBreaker(this Polly.CompositeStrategyBuilder! builder, Polly.CircuitBreaker.CircuitBreakerStrategyOptions! options) -> Polly.CompositeStrategyBuilder! +static Polly.CompositeStrategyBuilderExtensions.AddStrategy(this TBuilder! builder, Polly.ResilienceStrategy! strategy) -> TBuilder! +static Polly.CompositeStrategyBuilderExtensions.AddStrategy(this TBuilder! builder, System.Func! factory, Polly.ResilienceStrategyOptions! options) -> TBuilder! +static Polly.CompositeStrategyBuilderExtensions.AddStrategy(this Polly.CompositeStrategyBuilder! builder, Polly.ResilienceStrategy! strategy) -> Polly.CompositeStrategyBuilder! +static Polly.FallbackCompositeStrategyBuilderExtensions.AddFallback(this Polly.CompositeStrategyBuilder! builder, Polly.Fallback.FallbackStrategyOptions! options) -> Polly.CompositeStrategyBuilder! +static Polly.HedgingCompositeStrategyBuilderExtensions.AddHedging(this Polly.CompositeStrategyBuilder! builder, Polly.Hedging.HedgingStrategyOptions! options) -> Polly.CompositeStrategyBuilder! static Polly.Outcome.FromException(System.Exception! exception) -> Polly.Outcome static Polly.Outcome.FromExceptionAsTask(System.Exception! exception) -> System.Threading.Tasks.ValueTask> static Polly.Outcome.FromResult(TResult? value) -> Polly.Outcome @@ -399,13 +402,10 @@ static Polly.PredicateResult.True.get -> System.Threading.Tasks.ValueTask static Polly.ResilienceContextPool.Shared.get -> Polly.ResilienceContextPool! static Polly.ResiliencePropertyKey.operator !=(Polly.ResiliencePropertyKey left, Polly.ResiliencePropertyKey right) -> bool static Polly.ResiliencePropertyKey.operator ==(Polly.ResiliencePropertyKey left, Polly.ResiliencePropertyKey right) -> bool -static Polly.ResilienceStrategyBuilderExtensions.AddStrategy(this TBuilder! builder, Polly.ResilienceStrategy! strategy) -> TBuilder! -static Polly.ResilienceStrategyBuilderExtensions.AddStrategy(this TBuilder! builder, System.Func! factory, Polly.ResilienceStrategyOptions! options) -> TBuilder! -static Polly.ResilienceStrategyBuilderExtensions.AddStrategy(this Polly.ResilienceStrategyBuilder! builder, Polly.ResilienceStrategy! strategy) -> Polly.ResilienceStrategyBuilder! -static Polly.RetryResilienceStrategyBuilderExtensions.AddRetry(this Polly.ResilienceStrategyBuilder! builder, Polly.Retry.RetryStrategyOptions! options) -> Polly.ResilienceStrategyBuilder! -static Polly.RetryResilienceStrategyBuilderExtensions.AddRetry(this Polly.ResilienceStrategyBuilder! builder, Polly.Retry.RetryStrategyOptions! options) -> Polly.ResilienceStrategyBuilder! -static Polly.TimeoutResilienceStrategyBuilderExtensions.AddTimeout(this TBuilder! builder, Polly.Timeout.TimeoutStrategyOptions! options) -> TBuilder! -static Polly.TimeoutResilienceStrategyBuilderExtensions.AddTimeout(this TBuilder! builder, System.TimeSpan timeout) -> TBuilder! +static Polly.RetryCompositeStrategyBuilderExtensions.AddRetry(this Polly.CompositeStrategyBuilder! builder, Polly.Retry.RetryStrategyOptions! options) -> Polly.CompositeStrategyBuilder! +static Polly.RetryCompositeStrategyBuilderExtensions.AddRetry(this Polly.CompositeStrategyBuilder! builder, Polly.Retry.RetryStrategyOptions! options) -> Polly.CompositeStrategyBuilder! +static Polly.TimeoutCompositeStrategyBuilderExtensions.AddTimeout(this TBuilder! builder, Polly.Timeout.TimeoutStrategyOptions! options) -> TBuilder! +static Polly.TimeoutCompositeStrategyBuilderExtensions.AddTimeout(this TBuilder! builder, System.TimeSpan timeout) -> TBuilder! static Polly.Utils.LegacySupport.SetProperties(this Polly.ResilienceProperties! resilienceProperties, System.Collections.Generic.IDictionary! properties, out System.Collections.Generic.IDictionary! oldProperties) -> void static readonly Polly.NullResilienceStrategy.Instance -> Polly.NullResilienceStrategy! static readonly Polly.NullResilienceStrategy.Instance -> Polly.NullResilienceStrategy! diff --git a/src/Polly.Core/README.md b/src/Polly.Core/README.md index f5e8b0e9e6e..0fca0f8061a 100644 --- a/src/Polly.Core/README.md +++ b/src/Polly.Core/README.md @@ -134,22 +134,22 @@ Polly also exposes the sealed `ResilienceStrategy` strategy that is just a si This API exposes the following builders: -- [ResilienceStrategyBuilder](ResilienceStrategyBuilder.cs): Used to create resilience strategies that can execute all types of callbacks. In general, these strategies only handle exceptions. -- [ResilienceStrategyBuilder](ResilienceStrategyBuilder.TResult.cs): Used to create generic resilience strategies that can only execute callbacks that return the same result type. -- [ResilienceStrategyBuilderBase](ResilienceStrategyBuilderBase.cs): The base class for both builders above. You can use it as a target for strategy extensions that work for both builders above. +- [CompositeStrategyBuilder](CompositeStrategyBuilder.cs): Used to create resilience strategies that can execute all types of callbacks. In general, these strategies only handle exceptions. +- [CompositeStrategyBuilder](CompositeStrategyBuilder.TResult.cs): Used to create generic resilience strategies that can only execute callbacks that return the same result type. +- [CompositeStrategyBuilderBase](CompositeStrategyBuilderBase.cs): The base class for both builders above. You can use it as a target for strategy extensions that work for both builders above. -To create a strategy or pipeline of strategies you chain various extensions for `ResilienceStrategyBuilder` followed by the `Build` call: +To create a strategy or composite resilience strategy you chain various extensions for `CompositeStrategyBuilder` followed by the `Build` call: Single strategy: ``` csharp -var resilienceStrategy = new ResilienceStrategyBuilder().AddRetry().Build(); +var resilienceStrategy = new CompositeStrategyBuilder().AddRetry().Build(); ``` -Pipeline of strategies: +Composite strategy: ``` csharp -var resilienceStrategy = new ResilienceStrategyBuilder() +var resilienceStrategy = new CompositeStrategyBuilder() .AddRetry() .AddCircuitBreaker() .AddTimeout(new TimeoutStrategyOptions() { ... }) @@ -158,13 +158,13 @@ var resilienceStrategy = new ResilienceStrategyBuilder() ## Extensibility -The resilience extensibility is simple. You just expose extensions for `ResilienceStrategyBuilder` that use the `ResilienceStrategyBuilder.AddStrategy` methods. +The resilience extensibility is simple. You just expose extensions for `CompositeStrategyBuilder` that use the `CompositeStrategyBuilder.AddStrategy` methods. -If you want to create a resilience strategy that works for both generic and non-generic builders you can use `ResilienceStrategyBuilderBase` as a target: +If you want to create a resilience strategy that works for both generic and non-generic builders you can use `CompositeStrategyBuilderBase` as a target: ``` csharp public static TBuilder AddMyStrategy(this TBuilder builder) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { return builder.AddStrategy(new MyStrategy()); } @@ -211,7 +211,7 @@ Below are a few examples showcasing the usage of these delegates: A non-generic predicate defining retries for multiple result types: ``` csharp -new ResilienceStrategyBuilder() +new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { ShouldRetry = args => args switch @@ -228,7 +228,7 @@ new ResilienceStrategyBuilder() A generic predicate defining retries for a single result type: ``` csharp -new ResilienceStrategyBuilder() +new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { ShouldRetry = args => args switch @@ -248,6 +248,6 @@ When setting the delegates, ensure to respect the `ResilienceContext.IsSynchrono ## Telemetry Each individual resilience strategy can emit telemetry by using the [`ResilienceStrategyTelemetry`](Telemetry/ResilienceStrategyTelemetry.cs) API. Polly wraps the arguments as [`TelemetryEventArguments`](Telemetry/TelemetryEventArguments.cs) and emits them using `DiagnosticSource`. -To consume the telemetry, Polly adopters needs to assign an instance of `DiagnosticSource` to `ResilienceStrategyBuilder.DiagnosticSource` and consume `TelemetryEventArguments`. +To consume the telemetry, Polly adopters needs to assign an instance of `DiagnosticSource` to `CompositeStrategyBuilder.DiagnosticSource` and consume `TelemetryEventArguments`. -For common use-cases, it is anticipated that Polly users would leverage `Polly.Extensions`. This allows all of the aforementioned functionalities by invoking the `ResilienceStrategyBuilder.ConfigureTelemetry(...)` extension method. `ConfigureTelemetry` processes `TelemetryEventArguments` and generates logs and metrics from it. +For common use-cases, it is anticipated that Polly users would leverage `Polly.Extensions`. This allows all of the aforementioned functionalities by invoking the `CompositeStrategyBuilder.ConfigureTelemetry(...)` extension method. `ConfigureTelemetry` processes `TelemetryEventArguments` and generates logs and metrics from it. diff --git a/src/Polly.Core/Registry/ResilienceStrategyRegistry.TResult.cs b/src/Polly.Core/Registry/ResilienceStrategyRegistry.TResult.cs index ca16feb5f7c..e95d6b81f28 100644 --- a/src/Polly.Core/Registry/ResilienceStrategyRegistry.TResult.cs +++ b/src/Polly.Core/Registry/ResilienceStrategyRegistry.TResult.cs @@ -7,22 +7,22 @@ public sealed partial class ResilienceStrategyRegistry : ResilienceStrateg { private sealed class GenericRegistry { - private readonly Func> _activator; - private readonly ConcurrentDictionary, ConfigureBuilderContext>> _builders; + private readonly Func> _activator; + private readonly ConcurrentDictionary, ConfigureBuilderContext>> _builders; private readonly ConcurrentDictionary> _strategies; private readonly Func _builderNameFormatter; private readonly Func? _instanceNameFormatter; public GenericRegistry( - Func> activator, + Func> activator, IEqualityComparer builderComparer, IEqualityComparer strategyComparer, Func builderNameFormatter, Func? instanceNameFormatter) { _activator = activator; - _builders = new ConcurrentDictionary, ConfigureBuilderContext>>(builderComparer); + _builders = new ConcurrentDictionary, ConfigureBuilderContext>>(builderComparer); _strategies = new ConcurrentDictionary>(strategyComparer); _builderNameFormatter = builderNameFormatter; _instanceNameFormatter = instanceNameFormatter; @@ -49,7 +49,7 @@ public bool TryGet(TKey key, [NotNullWhen(true)] out ResilienceStrategy return false; } - public ResilienceStrategy GetOrAdd(TKey key, Action, ConfigureBuilderContext> configure) + public ResilienceStrategy GetOrAdd(TKey key, Action, ConfigureBuilderContext> configure) { var context = new ConfigureBuilderContext(key, _builderNameFormatter(key), _instanceNameFormatter?.Invoke(key)); @@ -64,7 +64,7 @@ public ResilienceStrategy GetOrAdd(TKey key, Action, ConfigureBuilderContext> configure) => _builders.TryAdd(key, configure); + public bool TryAddBuilder(TKey key, Action, ConfigureBuilderContext> configure) => _builders.TryAdd(key, configure); public bool RemoveBuilder(TKey key) => _builders.TryRemove(key, out _); diff --git a/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs b/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs index 00b0c92dc8f..23f5c0d9791 100644 --- a/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs +++ b/src/Polly.Core/Registry/ResilienceStrategyRegistry.cs @@ -12,15 +12,15 @@ namespace Polly.Registry; /// This class provides a way to organize and manage multiple resilience strategies /// using keys of type . /// -/// Additionally, it allows registration of callbacks that configure the strategy using . +/// Additionally, it allows registration of callbacks that configure the strategy using . /// These callbacks are called when the resilience strategy is not yet cached and it's retrieved for the first time. /// /// public sealed partial class ResilienceStrategyRegistry : ResilienceStrategyProvider where TKey : notnull { - private readonly Func _activator; - private readonly ConcurrentDictionary>> _builders; + private readonly Func _activator; + private readonly ConcurrentDictionary>> _builders; private readonly ConcurrentDictionary _strategies; private readonly ConcurrentDictionary _genericRegistry = new(); @@ -52,7 +52,7 @@ public ResilienceStrategyRegistry(ResilienceStrategyRegistryOptions option Guard.NotNull(options.BuilderNameFormatter); _activator = options.BuilderFactory; - _builders = new ConcurrentDictionary>>(options.BuilderComparer); + _builders = new ConcurrentDictionary>>(options.BuilderComparer); _strategies = new ConcurrentDictionary(options.StrategyComparer); _instanceNameFormatter = options.InstanceNameFormatter; _builderNameFormatter = options.BuilderNameFormatter; @@ -134,7 +134,7 @@ public override bool TryGetStrategy(TKey key, [NotNullWhen(true)] out Resilience /// The key used to identify the resilience strategy. /// The callback that configures the strategy builder. /// An instance of strategy. - public ResilienceStrategy GetOrAddStrategy(TKey key, Action configure) + public ResilienceStrategy GetOrAddStrategy(TKey key, Action configure) { Guard.NotNull(configure); @@ -147,7 +147,7 @@ public ResilienceStrategy GetOrAddStrategy(TKey key, ActionThe key used to identify the resilience strategy. /// The callback that configures the strategy builder. /// An instance of strategy. - public ResilienceStrategy GetOrAddStrategy(TKey key, Action> configure) + public ResilienceStrategy GetOrAddStrategy(TKey key, Action> configure) { Guard.NotNull(configure); @@ -176,7 +176,7 @@ public ResilienceStrategy GetOrAddStrategy(TKey key, ActionThe key used to identify the resilience strategy. /// The callback that configures the strategy builder. /// An instance of strategy. - public ResilienceStrategy GetOrAddStrategy(TKey key, Action> configure) + public ResilienceStrategy GetOrAddStrategy(TKey key, Action> configure) { Guard.NotNull(configure); @@ -190,7 +190,7 @@ public ResilienceStrategy GetOrAddStrategy(TKey key, ActionThe key used to identify the resilience strategy. /// The callback that configures the strategy builder. /// An instance of strategy. - public ResilienceStrategy GetOrAddStrategy(TKey key, Action, ConfigureBuilderContext> configure) + public ResilienceStrategy GetOrAddStrategy(TKey key, Action, ConfigureBuilderContext> configure) { Guard.NotNull(configure); @@ -207,7 +207,7 @@ public ResilienceStrategy GetOrAddStrategy(TKey key, Action /// Thrown when is . - public bool TryAddBuilder(TKey key, Action> configure) + public bool TryAddBuilder(TKey key, Action> configure) { Guard.NotNull(configure); @@ -225,7 +225,7 @@ public bool TryAddBuilder(TKey key, Action /// Thrown when is . - public bool TryAddBuilder(TKey key, Action, ConfigureBuilderContext> configure) + public bool TryAddBuilder(TKey key, Action, ConfigureBuilderContext> configure) { Guard.NotNull(configure); @@ -268,7 +268,7 @@ private static ResilienceStrategy CreateStrategy( Func activator, ConfigureBuilderContext context, Action> configure) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Func factory = () => { @@ -311,7 +311,7 @@ private GenericRegistry GetGenericRegistry() return (GenericRegistry)_genericRegistry.GetOrAdd(typeof(TResult), _ => { return new GenericRegistry( - () => new ResilienceStrategyBuilder(_activator()), + () => new CompositeStrategyBuilder(_activator()), _builderComparer, _strategyComparer, _builderNameFormatter, diff --git a/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs b/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs index bdc4be5553d..1c721f302d1 100644 --- a/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs +++ b/src/Polly.Core/Registry/ResilienceStrategyRegistryOptions.cs @@ -9,13 +9,13 @@ namespace Polly.Registry; public class ResilienceStrategyRegistryOptions { /// - /// Gets or sets the factory method that creates instances of . + /// Gets or sets the factory method that creates instances of . /// /// - /// The default value is a function that creates a new instance of using the default constructor. + /// The default value is a function that creates a new instance of using the default constructor. /// [Required] - public Func BuilderFactory { get; set; } = static () => new ResilienceStrategyBuilder(); + public Func BuilderFactory { get; set; } = static () => new CompositeStrategyBuilder(); /// /// Gets or sets the comparer that is used by the registry to retrieve the resilience strategies. diff --git a/src/Polly.Core/Retry/RetryResilienceStrategyBuilderExtensions.cs b/src/Polly.Core/Retry/RetryCompositeStrategyBuilderExtensions.cs similarity index 83% rename from src/Polly.Core/Retry/RetryResilienceStrategyBuilderExtensions.cs rename to src/Polly.Core/Retry/RetryCompositeStrategyBuilderExtensions.cs index 4038621b28c..95309303488 100644 --- a/src/Polly.Core/Retry/RetryResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Core/Retry/RetryCompositeStrategyBuilderExtensions.cs @@ -5,9 +5,9 @@ namespace Polly; /// -/// Retry extension methods for the . +/// Retry extension methods for the . /// -public static class RetryResilienceStrategyBuilderExtensions +public static class RetryCompositeStrategyBuilderExtensions { /// /// Adds a retry strategy to the builder. @@ -17,7 +17,7 @@ public static class RetryResilienceStrategyBuilderExtensions /// The builder instance with the retry strategy added. /// Thrown when or is . /// Thrown when are invalid. - public static ResilienceStrategyBuilder AddRetry(this ResilienceStrategyBuilder builder, RetryStrategyOptions options) + public static CompositeStrategyBuilder AddRetry(this CompositeStrategyBuilder builder, RetryStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -35,7 +35,7 @@ public static ResilienceStrategyBuilder AddRetry(this ResilienceStrategyBuilder /// The builder instance with the retry strategy added. /// Thrown when or is . /// Thrown when are invalid. - public static ResilienceStrategyBuilder AddRetry(this ResilienceStrategyBuilder builder, RetryStrategyOptions options) + public static CompositeStrategyBuilder AddRetry(this CompositeStrategyBuilder builder, RetryStrategyOptions options) { Guard.NotNull(builder); Guard.NotNull(options); @@ -49,7 +49,7 @@ public static ResilienceStrategyBuilder AddRetry(this Resilien "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "All options members preserved.")] private static void AddRetryCore( - this ResilienceStrategyBuilderBase builder, + this CompositeStrategyBuilderBase builder, RetryStrategyOptions options) { builder.AddStrategy(context => diff --git a/src/Polly.Core/ResilienceStrategyBuilderContext.cs b/src/Polly.Core/StrategyBuilderContext.cs similarity index 94% rename from src/Polly.Core/ResilienceStrategyBuilderContext.cs rename to src/Polly.Core/StrategyBuilderContext.cs index 63a47762bf7..f0e65a2f608 100644 --- a/src/Polly.Core/ResilienceStrategyBuilderContext.cs +++ b/src/Polly.Core/StrategyBuilderContext.cs @@ -7,9 +7,9 @@ namespace Polly; /// /// The context used for building an individual resilience strategy. /// -public sealed class ResilienceStrategyBuilderContext +public sealed class StrategyBuilderContext { - internal ResilienceStrategyBuilderContext( + internal StrategyBuilderContext( string? builderName, string? builderInstanceName, ResilienceProperties builderProperties, diff --git a/src/Polly.Core/Timeout/TimeoutResilienceStrategyBuilderExtensions.cs b/src/Polly.Core/Timeout/TimeoutCompositeStrategyBuilderExtensions.cs similarity index 90% rename from src/Polly.Core/Timeout/TimeoutResilienceStrategyBuilderExtensions.cs rename to src/Polly.Core/Timeout/TimeoutCompositeStrategyBuilderExtensions.cs index 1b928dcaf81..4016efea388 100644 --- a/src/Polly.Core/Timeout/TimeoutResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Core/Timeout/TimeoutCompositeStrategyBuilderExtensions.cs @@ -5,9 +5,9 @@ namespace Polly; /// -/// Extension methods for adding timeouts to a . +/// Extension methods for adding timeouts to a . /// -public static class TimeoutResilienceStrategyBuilderExtensions +public static class TimeoutCompositeStrategyBuilderExtensions { /// /// Adds a timeout resilience strategy to the builder. @@ -19,7 +19,7 @@ public static class TimeoutResilienceStrategyBuilderExtensions /// Thrown when is . /// Thrown when the options produced from the arguments are invalid. public static TBuilder AddTimeout(this TBuilder builder, TimeSpan timeout) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); @@ -44,7 +44,7 @@ public static TBuilder AddTimeout(this TBuilder builder, TimeSpan time "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "All options members preserved.")] public static TBuilder AddTimeout(this TBuilder builder, TimeoutStrategyOptions options) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(options); diff --git a/src/Polly.Core/Utils/ResilienceStrategyPipeline.cs b/src/Polly.Core/Utils/CompositeResilienceStrategy.cs similarity index 75% rename from src/Polly.Core/Utils/ResilienceStrategyPipeline.cs rename to src/Polly.Core/Utils/CompositeResilienceStrategy.cs index a1be3c81592..664f51c88c0 100644 --- a/src/Polly.Core/Utils/ResilienceStrategyPipeline.cs +++ b/src/Polly.Core/Utils/CompositeResilienceStrategy.cs @@ -5,26 +5,26 @@ namespace Polly.Utils; #pragma warning disable S2302 // "nameof" should be used /// -/// A pipeline of strategies. +/// A combination of multiple resilience strategies. /// -[DebuggerDisplay("ResilienceStrategyPipeline, Strategies = {Strategies.Count}")] +[DebuggerDisplay("CompositeResilienceStrategy, Strategies = {Strategies.Count}")] [DebuggerTypeProxy(typeof(DebuggerProxy))] -internal sealed partial class ResilienceStrategyPipeline : ResilienceStrategy +internal sealed partial class CompositeResilienceStrategy : ResilienceStrategy { - private readonly ResilienceStrategy _pipeline; + private readonly ResilienceStrategy _firstStrategy; - public static ResilienceStrategyPipeline CreatePipeline(IReadOnlyList strategies) + public static CompositeResilienceStrategy Create(IReadOnlyList strategies) { Guard.NotNull(strategies); if (strategies.Count < 2) { - throw new InvalidOperationException("The resilience pipeline must contain at least two resilience strategies."); + throw new InvalidOperationException("The composite resilience strategy must contain at least two resilience strategies."); } if (strategies.Distinct().Count() != strategies.Count) { - throw new InvalidOperationException("The resilience pipeline must contain unique resilience strategies."); + throw new InvalidOperationException("The composite resilience strategy must contain unique resilience strategies."); } // convert all strategies to delegating ones (except the last one as it's not required) @@ -46,13 +46,13 @@ public static ResilienceStrategyPipeline CreatePipeline(IReadOnlyList strategies) + private CompositeResilienceStrategy(ResilienceStrategy first, IReadOnlyList strategies) { Strategies = strategies; - _pipeline = pipeline; + _firstStrategy = first; } public IReadOnlyList Strategies { get; } @@ -66,7 +66,7 @@ protected internal override ValueTask> ExecuteCore(new OperationCanceledException(context.CancellationToken).TrySetStackTrace()); } - return _pipeline.ExecuteCore(callback, context, state); + return _firstStrategy.ExecuteCore(callback, context, state); } /// diff --git a/src/Polly.Core/Utils/ResilienceStrategyPipeline.DebuggerProxy.cs b/src/Polly.Core/Utils/ResilienceStrategyPipeline.DebuggerProxy.cs index d8094e8d25c..8d93c4e20b6 100644 --- a/src/Polly.Core/Utils/ResilienceStrategyPipeline.DebuggerProxy.cs +++ b/src/Polly.Core/Utils/ResilienceStrategyPipeline.DebuggerProxy.cs @@ -1,12 +1,12 @@ namespace Polly.Utils; -internal partial class ResilienceStrategyPipeline +internal partial class CompositeResilienceStrategy { internal sealed class DebuggerProxy { - private readonly ResilienceStrategyPipeline _resilienceStrategy; + private readonly CompositeResilienceStrategy _resilienceStrategy; - public DebuggerProxy(ResilienceStrategyPipeline resilienceStrategy) => _resilienceStrategy = resilienceStrategy; + public DebuggerProxy(CompositeResilienceStrategy resilienceStrategy) => _resilienceStrategy = resilienceStrategy; [DebuggerBrowsable(DebuggerBrowsableState.RootHidden)] public IEnumerable Strategies => _resilienceStrategy.Strategies; diff --git a/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs b/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs index e8a93beadf4..9bdb85e82b5 100644 --- a/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs +++ b/src/Polly.Extensions/DependencyInjection/PollyServiceCollectionExtensions.cs @@ -35,7 +35,7 @@ public static class PollyServiceCollectionExtensions public static IServiceCollection AddResilienceStrategy( this IServiceCollection services, TKey key, - Action> configure) + Action> configure) where TKey : notnull { Guard.NotNull(services); @@ -64,7 +64,7 @@ public static IServiceCollection AddResilienceStrategy( public static IServiceCollection AddResilienceStrategy( this IServiceCollection services, TKey key, - Action, AddResilienceStrategyContext> configure) + Action, AddResilienceStrategyContext> configure) where TKey : notnull { Guard.NotNull(services); @@ -107,7 +107,7 @@ public static IServiceCollection AddResilienceStrategy( public static IServiceCollection AddResilienceStrategy( this IServiceCollection services, TKey key, - Action configure) + Action configure) where TKey : notnull { Guard.NotNull(services); @@ -135,7 +135,7 @@ public static IServiceCollection AddResilienceStrategy( public static IServiceCollection AddResilienceStrategy( this IServiceCollection services, TKey key, - Action> configure) + Action> configure) where TKey : notnull { Guard.NotNull(services); @@ -210,7 +210,7 @@ public static IServiceCollection AddResilienceStrategyRegistry(this IServi services.AddOptions(); services.Add(RegistryMarker.ServiceDescriptor); - services.AddResilienceStrategyBuilder(); + services.AddCompositeStrategyBuilder(); services.TryAddSingleton(serviceProvider => { @@ -233,13 +233,13 @@ public static IServiceCollection AddResilienceStrategyRegistry(this IServi .AddOptions>() .Configure((options, serviceProvider) => { - options.BuilderFactory = () => serviceProvider.GetRequiredService(); + options.BuilderFactory = () => serviceProvider.GetRequiredService(); }); return services; } - private static void AddResilienceStrategyBuilder(this IServiceCollection services) + private static void AddCompositeStrategyBuilder(this IServiceCollection services) { services .AddOptions() @@ -250,7 +250,7 @@ private static void AddResilienceStrategyBuilder(this IServiceCollection service services.TryAddTransient(serviceProvider => { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder.Properties.Set(PollyDependencyInjectionKeys.ServiceProvider, serviceProvider); builder.ConfigureTelemetry(serviceProvider.GetRequiredService>().Value); return builder; diff --git a/src/Polly.Extensions/PublicAPI.Unshipped.txt b/src/Polly.Extensions/PublicAPI.Unshipped.txt index f1a30fc7840..b8417fbbf60 100644 --- a/src/Polly.Extensions/PublicAPI.Unshipped.txt +++ b/src/Polly.Extensions/PublicAPI.Unshipped.txt @@ -21,13 +21,13 @@ Polly.Extensions.Telemetry.TelemetryOptions.ResultFormatter.get -> System.Func

void Polly.Extensions.Telemetry.TelemetryOptions.TelemetryOptions() -> void Polly.PollyServiceCollectionExtensions -Polly.TelemetryResilienceStrategyBuilderExtensions +Polly.TelemetryCompositeStrategyBuilderExtensions static Polly.Extensions.Registry.ConfigureBuilderContextExtensions.EnableReloads(this Polly.Registry.ConfigureBuilderContext! context, Microsoft.Extensions.Options.IOptionsMonitor! optionsMonitor, string? name = null) -> void -static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action!, Polly.Extensions.DependencyInjection.AddResilienceStrategyContext!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! +static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action!, Polly.Extensions.DependencyInjection.AddResilienceStrategyContext!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! +static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! +static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! +static Polly.PollyServiceCollectionExtensions.AddResilienceStrategy(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, TKey key, System.Action! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Polly.PollyServiceCollectionExtensions.AddResilienceStrategyRegistry(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! static Polly.PollyServiceCollectionExtensions.AddResilienceStrategyRegistry(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services, System.Action!>! configure) -> Microsoft.Extensions.DependencyInjection.IServiceCollection! -static Polly.TelemetryResilienceStrategyBuilderExtensions.ConfigureTelemetry(this TBuilder! builder, Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> TBuilder! -static Polly.TelemetryResilienceStrategyBuilderExtensions.ConfigureTelemetry(this TBuilder! builder, Polly.Extensions.Telemetry.TelemetryOptions! options) -> TBuilder! +static Polly.TelemetryCompositeStrategyBuilderExtensions.ConfigureTelemetry(this TBuilder! builder, Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> TBuilder! +static Polly.TelemetryCompositeStrategyBuilderExtensions.ConfigureTelemetry(this TBuilder! builder, Polly.Extensions.Telemetry.TelemetryOptions! options) -> TBuilder! diff --git a/src/Polly.Extensions/README.md b/src/Polly.Extensions/README.md index 49403c63ed0..0215b86124b 100644 --- a/src/Polly.Extensions/README.md +++ b/src/Polly.Extensions/README.md @@ -49,7 +49,7 @@ telemetryOptions.OnTelemetryEvent = args => Console.WriteLine($"Telemetry event occurred: {args.Event.EventName}"); }); -var builder = new ResilienceStrategyBuilder() +var builder = new CompositeStrategyBuilder() .AddTimeout(TimeSpan.FromSeconds(1)) .ConfigureTelemetry(telemetryOptions) // This method enables telemetry in the builder .Build(); diff --git a/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs b/src/Polly.Extensions/Telemetry/TelemetryCompositeStrategyBuilderExtensions.cs similarity index 87% rename from src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs rename to src/Polly.Extensions/Telemetry/TelemetryCompositeStrategyBuilderExtensions.cs index 7ee52d9f8d3..298f8d7c5db 100644 --- a/src/Polly.Extensions/Telemetry/TelemetryResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.Extensions/Telemetry/TelemetryCompositeStrategyBuilderExtensions.cs @@ -6,9 +6,9 @@ namespace Polly; ///

-/// The telemetry extensions for the . +/// The telemetry extensions for the . /// -public static class TelemetryResilienceStrategyBuilderExtensions +public static class TelemetryCompositeStrategyBuilderExtensions { /// /// Enables telemetry for this builder. @@ -19,11 +19,11 @@ public static class TelemetryResilienceStrategyBuilderExtensions /// The builder instance with the telemetry enabled. /// /// By enabling telemetry, the resilience strategy will log and meter all resilience events. - /// Additionally, the telemetry strategy that logs and meters the executions is added to the beginning of the strategy pipeline. + /// Additionally, the telemetry strategy that logs and meters the executions is added to the beginning of the composite strategy. /// /// Thrown when or is . public static TBuilder ConfigureTelemetry(this TBuilder builder, ILoggerFactory loggerFactory) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(loggerFactory); @@ -40,12 +40,12 @@ public static TBuilder ConfigureTelemetry(this TBuilder builder, ILogg /// The builder instance with the telemetry enabled. /// /// By enabling telemetry, the resilience strategy will log and meter all resilience events. - /// Additionally, the telemetry strategy that logs and meters the executions is added to the beginning of the strategy pipeline. + /// Additionally, the telemetry strategy that logs and meters the executions is added to the beginning of the composite strategy. /// /// Thrown when or is . [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(TelemetryOptions))] public static TBuilder ConfigureTelemetry(this TBuilder builder, TelemetryOptions options) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(options); diff --git a/src/Polly.RateLimiting/PublicAPI.Unshipped.txt b/src/Polly.RateLimiting/PublicAPI.Unshipped.txt index 39fd5fb4303..ddc915a0f9d 100644 --- a/src/Polly.RateLimiting/PublicAPI.Unshipped.txt +++ b/src/Polly.RateLimiting/PublicAPI.Unshipped.txt @@ -1,5 +1,5 @@ #nullable enable -Polly.RateLimiterResilienceStrategyBuilderExtensions +Polly.RateLimiterCompositeStrategyBuilderExtensions Polly.RateLimiting.OnRateLimiterRejectedArguments Polly.RateLimiting.OnRateLimiterRejectedArguments.Context.get -> Polly.ResilienceContext! Polly.RateLimiting.OnRateLimiterRejectedArguments.Lease.get -> System.Threading.RateLimiting.RateLimitLease! @@ -22,9 +22,9 @@ Polly.RateLimiting.RateLimiterStrategyOptions.RateLimiter.get -> Polly.RateLimit Polly.RateLimiting.RateLimiterStrategyOptions.RateLimiter.set -> void Polly.RateLimiting.RateLimiterStrategyOptions.RateLimiterStrategyOptions() -> void Polly.RateLimiting.ResilienceRateLimiter -static Polly.RateLimiterResilienceStrategyBuilderExtensions.AddConcurrencyLimiter(this TBuilder! builder, int permitLimit, int queueLimit = 0) -> TBuilder! -static Polly.RateLimiterResilienceStrategyBuilderExtensions.AddConcurrencyLimiter(this TBuilder! builder, System.Threading.RateLimiting.ConcurrencyLimiterOptions! options) -> TBuilder! -static Polly.RateLimiterResilienceStrategyBuilderExtensions.AddRateLimiter(this TBuilder! builder, Polly.RateLimiting.RateLimiterStrategyOptions! options) -> TBuilder! -static Polly.RateLimiterResilienceStrategyBuilderExtensions.AddRateLimiter(this TBuilder! builder, System.Threading.RateLimiting.RateLimiter! limiter) -> TBuilder! +static Polly.RateLimiterCompositeStrategyBuilderExtensions.AddConcurrencyLimiter(this TBuilder! builder, int permitLimit, int queueLimit = 0) -> TBuilder! +static Polly.RateLimiterCompositeStrategyBuilderExtensions.AddConcurrencyLimiter(this TBuilder! builder, System.Threading.RateLimiting.ConcurrencyLimiterOptions! options) -> TBuilder! +static Polly.RateLimiterCompositeStrategyBuilderExtensions.AddRateLimiter(this TBuilder! builder, Polly.RateLimiting.RateLimiterStrategyOptions! options) -> TBuilder! +static Polly.RateLimiterCompositeStrategyBuilderExtensions.AddRateLimiter(this TBuilder! builder, System.Threading.RateLimiting.RateLimiter! limiter) -> TBuilder! static Polly.RateLimiting.ResilienceRateLimiter.Create(System.Threading.RateLimiting.PartitionedRateLimiter! rateLimiter) -> Polly.RateLimiting.ResilienceRateLimiter! static Polly.RateLimiting.ResilienceRateLimiter.Create(System.Threading.RateLimiting.RateLimiter! rateLimiter) -> Polly.RateLimiting.ResilienceRateLimiter! diff --git a/src/Polly.RateLimiting/RateLimiterResilienceStrategyBuilderExtensions.cs b/src/Polly.RateLimiting/RateLimiterCompositeStrategyBuilderExtensions.cs similarity index 93% rename from src/Polly.RateLimiting/RateLimiterResilienceStrategyBuilderExtensions.cs rename to src/Polly.RateLimiting/RateLimiterCompositeStrategyBuilderExtensions.cs index 31211a2eeea..9fd4b28c39d 100644 --- a/src/Polly.RateLimiting/RateLimiterResilienceStrategyBuilderExtensions.cs +++ b/src/Polly.RateLimiting/RateLimiterCompositeStrategyBuilderExtensions.cs @@ -6,9 +6,9 @@ namespace Polly; /// -/// The rate limiter extensions for . +/// The rate limiter extensions for . /// -public static class RateLimiterResilienceStrategyBuilderExtensions +public static class RateLimiterCompositeStrategyBuilderExtensions { /// /// Adds the concurrency limiter strategy. @@ -25,7 +25,7 @@ public static TBuilder AddConcurrencyLimiter( this TBuilder builder, int permitLimit, int queueLimit = 0) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); @@ -49,7 +49,7 @@ public static TBuilder AddConcurrencyLimiter( public static TBuilder AddConcurrencyLimiter( this TBuilder builder, ConcurrencyLimiterOptions options) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(options); @@ -72,7 +72,7 @@ public static TBuilder AddConcurrencyLimiter( public static TBuilder AddRateLimiter( this TBuilder builder, RateLimiter limiter) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(limiter); @@ -101,7 +101,7 @@ public static TBuilder AddRateLimiter( public static TBuilder AddRateLimiter( this TBuilder builder, RateLimiterStrategyOptions options) - where TBuilder : ResilienceStrategyBuilderBase + where TBuilder : CompositeStrategyBuilderBase { Guard.NotNull(builder); Guard.NotNull(options); diff --git a/src/Polly.Testing/README.md b/src/Polly.Testing/README.md index fa1b42f68d0..6a474741700 100644 --- a/src/Polly.Testing/README.md +++ b/src/Polly.Testing/README.md @@ -4,7 +4,7 @@ This package exposes APIs and utilities that can be used to assert on the compos ``` csharp // Build your resilience strategy. -ResilienceStrategy strategy = new ResilienceStrategyBuilder() +ResilienceStrategy strategy = new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { RetryCount = 4 diff --git a/src/Polly.Testing/ResilienceStrategyExtensions.cs b/src/Polly.Testing/ResilienceStrategyExtensions.cs index 3f787e7a249..9f8f0b3bc89 100644 --- a/src/Polly.Testing/ResilienceStrategyExtensions.cs +++ b/src/Polly.Testing/ResilienceStrategyExtensions.cs @@ -48,7 +48,7 @@ public static InnerStrategiesDescriptor GetInnerStrategies(this ResilienceStrate private static void ExpandStrategies(this ResilienceStrategy strategy, List strategies) { - if (strategy is ResilienceStrategyPipeline pipeline) + if (strategy is CompositeResilienceStrategy pipeline) { foreach (var inner in pipeline.Strategies) { diff --git a/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerResilienceStrategyBuilderTests.cs b/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerCompositeStrategyBuilderTests.cs similarity index 80% rename from test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerResilienceStrategyBuilderTests.cs rename to test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerCompositeStrategyBuilderTests.cs index 0e0cac1de80..d79aeba9e92 100644 --- a/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerResilienceStrategyBuilderTests.cs +++ b/test/Polly.Core.Tests/CircuitBreaker/CircuitBreakerCompositeStrategyBuilderTests.cs @@ -4,9 +4,9 @@ namespace Polly.Core.Tests.CircuitBreaker; -public class CircuitBreakerResilienceStrategyBuilderTests +public class CircuitBreakerCompositeStrategyBuilderTests { - public static TheoryData> ConfigureData = new() + public static TheoryData> ConfigureData = new() { builder => builder.AddCircuitBreaker(new CircuitBreakerStrategyOptions { @@ -14,7 +14,7 @@ public class CircuitBreakerResilienceStrategyBuilderTests }), }; - public static TheoryData>> ConfigureDataGeneric = new() + public static TheoryData>> ConfigureDataGeneric = new() { builder => builder.AddCircuitBreaker(new CircuitBreakerStrategyOptions { @@ -24,9 +24,9 @@ public class CircuitBreakerResilienceStrategyBuilderTests [MemberData(nameof(ConfigureData))] [Theory] - public void AddCircuitBreaker_Configure(Action builderAction) + public void AddCircuitBreaker_Configure(Action builderAction) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builderAction(builder); @@ -37,9 +37,9 @@ public void AddCircuitBreaker_Configure(Action builde [MemberData(nameof(ConfigureDataGeneric))] [Theory] - public void AddCircuitBreaker_Generic_Configure(Action> builderAction) + public void AddCircuitBreaker_Generic_Configure(Action> builderAction) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builderAction(builder); @@ -51,12 +51,12 @@ public void AddCircuitBreaker_Generic_Configure(Action() + new CompositeStrategyBuilder() .Invoking(b => b.AddCircuitBreaker(new CircuitBreakerStrategyOptions { BreakDuration = TimeSpan.MinValue })) .Should() .Throw(); - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .Invoking(b => b.AddCircuitBreaker(new CircuitBreakerStrategyOptions { BreakDuration = TimeSpan.MinValue })) .Should() .Throw(); @@ -82,7 +82,7 @@ public void AddCircuitBreaker_IntegrationTest() }; var timeProvider = new FakeTimeProvider(); - var strategy = new ResilienceStrategyBuilder { TimeProvider = timeProvider }.AddCircuitBreaker(options).Build(); + var strategy = new CompositeStrategyBuilder { TimeProvider = timeProvider }.AddCircuitBreaker(options).Build(); for (int i = 0; i < 10; i++) { @@ -117,11 +117,11 @@ public async Task AddCircuitBreakers_WithIsolatedManualControl_ShouldBeIsolated( var manualControl = new CircuitBreakerManualControl(); await manualControl.IsolateAsync(); - var strategy1 = new ResilienceStrategyBuilder() + var strategy1 = new CompositeStrategyBuilder() .AddCircuitBreaker(new() { ManualControl = manualControl }) .Build(); - var strategy2 = new ResilienceStrategyBuilder() + var strategy2 = new CompositeStrategyBuilder() .AddCircuitBreaker(new() { ManualControl = manualControl }) .Build(); diff --git a/test/Polly.Core.Tests/ResilienceStrategyBuilderContextTests.cs b/test/Polly.Core.Tests/CompositeStrategyBuilderContextTests.cs similarity index 80% rename from test/Polly.Core.Tests/ResilienceStrategyBuilderContextTests.cs rename to test/Polly.Core.Tests/CompositeStrategyBuilderContextTests.cs index d3467cdd1ff..7e4551a1e90 100644 --- a/test/Polly.Core.Tests/ResilienceStrategyBuilderContextTests.cs +++ b/test/Polly.Core.Tests/CompositeStrategyBuilderContextTests.cs @@ -3,14 +3,14 @@ namespace Polly.Core.Tests; -public class ResilienceStrategyBuilderContextTests +public class CompositeStrategyBuilderContextTests { [Fact] public void Ctor_EnsureDefaults() { var properties = new ResilienceProperties(); var timeProvider = new FakeTimeProvider(); - var context = new ResilienceStrategyBuilderContext("builder-name", "instance", properties, "strategy-name", timeProvider, Mock.Of(), () => 1.0); + var context = new StrategyBuilderContext("builder-name", "instance", properties, "strategy-name", timeProvider, Mock.Of(), () => 1.0); context.BuilderName.Should().Be("builder-name"); context.BuilderInstanceName.Should().Be("instance"); diff --git a/test/Polly.Core.Tests/ResilienceStrategyBuilderTests.cs b/test/Polly.Core.Tests/CompositeStrategyBuilderTests.cs similarity index 86% rename from test/Polly.Core.Tests/ResilienceStrategyBuilderTests.cs rename to test/Polly.Core.Tests/CompositeStrategyBuilderTests.cs index 71f6396d0ce..255ca5b58e8 100644 --- a/test/Polly.Core.Tests/ResilienceStrategyBuilderTests.cs +++ b/test/Polly.Core.Tests/CompositeStrategyBuilderTests.cs @@ -6,12 +6,12 @@ namespace Polly.Core.Tests; -public class ResilienceStrategyBuilderTests +public class CompositeStrategyBuilderTests { [Fact] public void Ctor_EnsureDefaults() { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder.Name.Should().BeNull(); builder.Properties.Should().NotBeNull(); @@ -22,7 +22,7 @@ public void Ctor_EnsureDefaults() [Fact] public void CopyCtor_Ok() { - var builder = new ResilienceStrategyBuilder + var builder = new CompositeStrategyBuilder { TimeProvider = Mock.Of(), Name = "dummy", @@ -33,7 +33,7 @@ public void CopyCtor_Ok() builder.Properties.Set(new ResiliencePropertyKey("dummy"), "dummy"); - var other = new ResilienceStrategyBuilder(builder); + var other = new CompositeStrategyBuilder(builder); other.Name.Should().Be(builder.Name); other.TimeProvider.Should().Be(builder.TimeProvider); other.Randomizer.Should().BeSameAs(builder.Randomizer); @@ -47,7 +47,7 @@ public void AddStrategy_Single_Ok() { // arrange var executions = new List(); - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); var first = new TestResilienceStrategy { Before = (_, _) => executions.Add(1), @@ -71,7 +71,7 @@ public void AddStrategy_Multiple_Ok() { // arrange var executions = new List(); - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); var first = new TestResilienceStrategy { Before = (_, _) => executions.Add(1), @@ -96,7 +96,7 @@ public void AddStrategy_Multiple_Ok() var strategy = builder.Build(); strategy .Should() - .BeOfType() + .BeOfType() .Subject .Strategies.Should().HaveCount(3); @@ -112,20 +112,20 @@ public void AddStrategy_Duplicate_Throws() { // arrange var executions = new List(); - var builder = new ResilienceStrategyBuilder() + var builder = new CompositeStrategyBuilder() .AddStrategy(NullResilienceStrategy.Instance) .AddStrategy(NullResilienceStrategy.Instance); builder.Invoking(b => b.Build()) .Should() .Throw() - .WithMessage("The resilience pipeline must contain unique resilience strategies."); + .WithMessage("The composite resilience strategy must contain unique resilience strategies."); } [Fact] public void Validator_Ok() { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder.Validator.Should().NotBeNull(); @@ -147,7 +147,7 @@ public void AddStrategy_MultipleNonDelegating_Ok() { // arrange var executions = new List(); - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); var first = new Strategy { Before = () => executions.Add(1), @@ -179,12 +179,12 @@ public void AddStrategy_MultipleNonDelegating_Ok() } [Fact] - public void Build_Empty_ReturnsNullResilienceStrategy() => new ResilienceStrategyBuilder().Build().Should().BeSameAs(NullResilienceStrategy.Instance); + public void Build_Empty_ReturnsNullResilienceStrategy() => new CompositeStrategyBuilder().Build().Should().BeSameAs(NullResilienceStrategy.Instance); [Fact] public void AddStrategy_AfterUsed_Throws() { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder.Build(); @@ -198,14 +198,14 @@ public void AddStrategy_AfterUsed_Throws() [Fact] public void Build_InvalidBuilderOptions_Throw() { - var builder = new InvalidResilienceStrategyBuilder(); + var builder = new InvalidCompositeStrategyBuilder(); builder.Invoking(b => b.BuildStrategy()) .Should() .Throw() .WithMessage( """ -The 'ResilienceStrategyBuilder' configuration is invalid. +The 'CompositeStrategyBuilder' configuration is invalid. Validation Errors: The RequiredProperty field is required. @@ -215,7 +215,7 @@ The RequiredProperty field is required. [Fact] public void AddStrategy_InvalidOptions_Throws() { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder .Invoking(b => b.AddStrategy(_ => NullResilienceStrategy.Instance, new InvalidResilienceStrategyOptions())) @@ -233,7 +233,7 @@ The RequiredProperty field is required. [Fact] public void AddStrategy_NullFactory_Throws() { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder .Invoking(b => b.AddStrategy(null!, new TestResilienceStrategyOptions())) @@ -260,17 +260,17 @@ public void AddStrategy_CombinePipelines_Ok() After = (_, _) => executions.Add(6), }; - var pipeline1 = new ResilienceStrategyBuilder().AddStrategy(first).AddStrategy(second).Build(); + var pipeline1 = new CompositeStrategyBuilder().AddStrategy(first).AddStrategy(second).Build(); var third = new TestResilienceStrategy { Before = (_, _) => executions.Add(3), After = (_, _) => executions.Add(5), }; - var pipeline2 = new ResilienceStrategyBuilder().AddStrategy(third).Build(); + var pipeline2 = new CompositeStrategyBuilder().AddStrategy(third).Build(); // act - var strategy = new ResilienceStrategyBuilder().AddStrategy(pipeline1).AddStrategy(pipeline2).Build(); + var strategy = new CompositeStrategyBuilder().AddStrategy(pipeline1).AddStrategy(pipeline2).Build(); // assert strategy.Execute(_ => executions.Add(4)); @@ -286,7 +286,7 @@ public void BuildStrategy_EnsureCorrectContext() var verified1 = false; var verified2 = false; - var builder = new ResilienceStrategyBuilder + var builder = new CompositeStrategyBuilder { Name = "builder-name", TimeProvider = new FakeTimeProvider(), @@ -334,7 +334,7 @@ public void Build_OnCreatingStrategy_EnsureRespected() { // arrange var strategy = new TestResilienceStrategy(); - var builder = new ResilienceStrategyBuilder + var builder = new CompositeStrategyBuilder { OnCreatingStrategy = strategies => { @@ -349,11 +349,11 @@ public void Build_OnCreatingStrategy_EnsureRespected() var finalStrategy = builder.Build(); // assert - finalStrategy.Should().BeOfType(); + finalStrategy.Should().BeOfType(); } [Fact] - public void EmptyOptions_Ok() => ResilienceStrategyBuilderExtensions.EmptyOptions.Instance.Name.Should().BeNull(); + public void EmptyOptions_Ok() => CompositeStrategyBuilderExtensions.EmptyOptions.Instance.Name.Should().BeNull(); [Fact] public void ExecuteAsync_EnsureReceivedCallbackExecutesNextStrategy() @@ -378,7 +378,7 @@ public void ExecuteAsync_EnsureReceivedCallbackExecutesNextStrategy() After = (_, _) => executions.Add("third-end"), }; - var strategy = new ResilienceStrategyBuilder().AddStrategy(first).AddStrategy(second).AddStrategy(third).Build(); + var strategy = new CompositeStrategyBuilder().AddStrategy(first).AddStrategy(second).AddStrategy(third).Build(); // act strategy.Execute(_ => executions.Add("execute")); @@ -454,7 +454,7 @@ private class InvalidResilienceStrategyOptions : ResilienceStrategyOptions public string? RequiredProperty { get; set; } } - private class InvalidResilienceStrategyBuilder : ResilienceStrategyBuilderBase + private class InvalidCompositeStrategyBuilder : CompositeStrategyBuilderBase { [Required] public string? RequiredProperty { get; set; } diff --git a/test/Polly.Core.Tests/Fallback/FallbackResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Fallback/FallbackCompositeStrategyBuilderExtensionsTests.cs similarity index 76% rename from test/Polly.Core.Tests/Fallback/FallbackResilienceStrategyBuilderExtensionsTests.cs rename to test/Polly.Core.Tests/Fallback/FallbackCompositeStrategyBuilderExtensionsTests.cs index d78615785f4..3ad664e5d23 100644 --- a/test/Polly.Core.Tests/Fallback/FallbackResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Fallback/FallbackCompositeStrategyBuilderExtensionsTests.cs @@ -3,9 +3,9 @@ namespace Polly.Core.Tests.Fallback; -public class FallbackResilienceStrategyBuilderExtensionsTests +public class FallbackCompositeStrategyBuilderExtensionsTests { - public static readonly TheoryData>> FallbackOverloadsGeneric = new() + public static readonly TheoryData>> FallbackOverloadsGeneric = new() { builder => { @@ -19,9 +19,9 @@ public class FallbackResilienceStrategyBuilderExtensionsTests [MemberData(nameof(FallbackOverloadsGeneric))] [Theory] - public void AddFallback_Generic_Ok(Action> configure) + public void AddFallback_Generic_Ok(Action> configure) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); configure(builder); builder.Build().Strategy.Should().BeOfType>(); } @@ -40,7 +40,7 @@ public void AddFallback_Ok() FallbackAction = _ => Outcome.FromResultAsTask((object)1) }; - var strategy = new ResilienceStrategyBuilder().AddFallback(options).Build(); + var strategy = new CompositeStrategyBuilder().AddFallback(options).Build(); strategy.Execute(_ => -1).Should().Be(1); strategy.Execute(_ => throw new InvalidOperationException()).Should().Be(1); @@ -49,7 +49,7 @@ public void AddFallback_Ok() [Fact] public void AddFallback_InvalidOptions_Throws() { - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .Invoking(b => b.AddFallback(new FallbackStrategyOptions())) .Should() .Throw(); @@ -58,7 +58,7 @@ public void AddFallback_InvalidOptions_Throws() [Fact] public void AddFallbackT_InvalidOptions_Throws() { - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .Invoking(b => b.AddFallback(new FallbackStrategyOptions())) .Should() .Throw(); diff --git a/test/Polly.Core.Tests/GenericResilienceStrategyBuilderTests.cs b/test/Polly.Core.Tests/GenericCompositeStrategyBuilderTests.cs similarity index 82% rename from test/Polly.Core.Tests/GenericResilienceStrategyBuilderTests.cs rename to test/Polly.Core.Tests/GenericCompositeStrategyBuilderTests.cs index aecc4ea33dc..e7e56546fed 100644 --- a/test/Polly.Core.Tests/GenericResilienceStrategyBuilderTests.cs +++ b/test/Polly.Core.Tests/GenericCompositeStrategyBuilderTests.cs @@ -3,9 +3,9 @@ namespace Polly.Core.Tests; -public class GenericResilienceStrategyBuilderTests +public class GenericCompositeStrategyBuilderTests { - private readonly ResilienceStrategyBuilder _builder = new(); + private readonly CompositeStrategyBuilder _builder = new(); [Fact] public void Ctor_EnsureDefaults() @@ -19,7 +19,7 @@ public void Ctor_EnsureDefaults() [Fact] public void CopyCtor_Ok() { - new ResilienceStrategyBuilder(new ResilienceStrategyBuilder()).Should().NotBeNull(); + new CompositeStrategyBuilder(new CompositeStrategyBuilder()).Should().NotBeNull(); } [Fact] @@ -48,7 +48,7 @@ public void Build_Ok() // assert strategy.Should().NotBeNull(); - strategy.Strategy.Should().BeOfType().Subject.Strategies.Should().HaveCount(2); + strategy.Strategy.Should().BeOfType().Subject.Strategies.Should().HaveCount(2); } [Fact] diff --git a/test/Polly.Core.Tests/Hedging/HedgingResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Hedging/HedgingCompositeStrategyBuilderExtensionsTests.cs similarity index 94% rename from test/Polly.Core.Tests/Hedging/HedgingResilienceStrategyBuilderExtensionsTests.cs rename to test/Polly.Core.Tests/Hedging/HedgingCompositeStrategyBuilderExtensionsTests.cs index a1b77af6729..cc7224c0032 100644 --- a/test/Polly.Core.Tests/Hedging/HedgingResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Hedging/HedgingCompositeStrategyBuilderExtensionsTests.cs @@ -3,10 +3,10 @@ namespace Polly.Core.Tests.Hedging; -public class HedgingResilienceStrategyBuilderExtensionsTests +public class HedgingCompositeStrategyBuilderExtensionsTests { - private readonly ResilienceStrategyBuilder _builder = new(); - private readonly ResilienceStrategyBuilder _genericBuilder = new(); + private readonly CompositeStrategyBuilder _builder = new(); + private readonly CompositeStrategyBuilder _genericBuilder = new(); [Fact] public void AddHedging_Ok() diff --git a/test/Polly.Core.Tests/Issues/IssuesTests.CircuitBreakerStateSharing_959.cs b/test/Polly.Core.Tests/Issues/IssuesTests.CircuitBreakerStateSharing_959.cs index c2425ebdb51..6826a9092e6 100644 --- a/test/Polly.Core.Tests/Issues/IssuesTests.CircuitBreakerStateSharing_959.cs +++ b/test/Polly.Core.Tests/Issues/IssuesTests.CircuitBreakerStateSharing_959.cs @@ -23,7 +23,7 @@ public void CircuitBreakerStateSharing_959() }; // create the strategy - var strategy = new ResilienceStrategyBuilder { TimeProvider = TimeProvider }.AddCircuitBreaker(options).Build(); + var strategy = new CompositeStrategyBuilder { TimeProvider = TimeProvider }.AddCircuitBreaker(options).Build(); // now trigger the circuit breaker by evaluating multiple result types for (int i = 0; i < 5; i++) diff --git a/test/Polly.Core.Tests/Issues/IssuesTests.FlowingContext_849.cs b/test/Polly.Core.Tests/Issues/IssuesTests.FlowingContext_849.cs index 9feb9bd5c9c..2b0d9d854b2 100644 --- a/test/Polly.Core.Tests/Issues/IssuesTests.FlowingContext_849.cs +++ b/test/Polly.Core.Tests/Issues/IssuesTests.FlowingContext_849.cs @@ -8,7 +8,7 @@ public partial class IssuesTests public void FlowingContext_849() { var contextChecked = false; - var strategy = new ResilienceStrategyBuilder() + var strategy = new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { // configure the predicate and use the context diff --git a/test/Polly.Core.Tests/Issues/IssuesTests.HandleMultipleResults_898.cs b/test/Polly.Core.Tests/Issues/IssuesTests.HandleMultipleResults_898.cs index 461e15bf04b..fbef041d037 100644 --- a/test/Polly.Core.Tests/Issues/IssuesTests.HandleMultipleResults_898.cs +++ b/test/Polly.Core.Tests/Issues/IssuesTests.HandleMultipleResults_898.cs @@ -31,7 +31,7 @@ public void HandleMultipleResults_898() }; // create the strategy - var strategy = new ResilienceStrategyBuilder().AddRetry(options).Build(); + var strategy = new CompositeStrategyBuilder().AddRetry(options).Build(); // check that int-based results is retried bool isRetry = false; diff --git a/test/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs b/test/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs index 15bbbd8fdc5..69fc6477b4c 100644 --- a/test/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs +++ b/test/Polly.Core.Tests/Registry/ResilienceStrategyRegistryTests.cs @@ -9,13 +9,13 @@ public class ResilienceStrategyRegistryTests { private readonly ResilienceStrategyRegistryOptions _options; - private Action _callback = _ => { }; + private Action _callback = _ => { }; public ResilienceStrategyRegistryTests() => _options = new() { BuilderFactory = () => { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); _callback(builder); return builder; }, diff --git a/test/Polly.Core.Tests/ResilienceStrategyTests.cs b/test/Polly.Core.Tests/ResilienceStrategyTests.cs index fb2377a9b74..d138337f836 100644 --- a/test/Polly.Core.Tests/ResilienceStrategyTests.cs +++ b/test/Polly.Core.Tests/ResilienceStrategyTests.cs @@ -33,13 +33,13 @@ await TestUtilities.AssertWithTimeoutAsync(async () => [Fact] public void DebuggerProxy_Ok() { - var pipeline = ResilienceStrategyPipeline.CreatePipeline(new[] + var pipeline = CompositeResilienceStrategy.Create(new[] { new TestResilienceStrategy(), new TestResilienceStrategy() }); - new ResilienceStrategyPipeline.DebuggerProxy(pipeline).Strategies.Should().HaveCount(2); + new CompositeResilienceStrategy.DebuggerProxy(pipeline).Strategies.Should().HaveCount(2); } public class ExecuteParameters : ExecuteParameters diff --git a/test/Polly.Core.Tests/Retry/RetryResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Retry/RetryCompositeStrategyBuilderExtensionsTests.cs similarity index 77% rename from test/Polly.Core.Tests/Retry/RetryResilienceStrategyBuilderExtensionsTests.cs rename to test/Polly.Core.Tests/Retry/RetryCompositeStrategyBuilderExtensionsTests.cs index c652fb260d3..fa4cfc8131d 100644 --- a/test/Polly.Core.Tests/Retry/RetryResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Retry/RetryCompositeStrategyBuilderExtensionsTests.cs @@ -5,9 +5,9 @@ namespace Polly.Core.Tests.Retry; #pragma warning disable CA2012 // Use ValueTasks correctly -public class RetryResilienceStrategyBuilderExtensionsTests +public class RetryCompositeStrategyBuilderExtensionsTests { - public static readonly TheoryData> OverloadsData = new() + public static readonly TheoryData> OverloadsData = new() { builder => { @@ -23,7 +23,7 @@ public class RetryResilienceStrategyBuilderExtensionsTests } }; - public static readonly TheoryData>> OverloadsDataGeneric = new() + public static readonly TheoryData>> OverloadsDataGeneric = new() { builder => { @@ -41,18 +41,18 @@ public class RetryResilienceStrategyBuilderExtensionsTests [MemberData(nameof(OverloadsData))] [Theory] - public void AddRetry_Overloads_Ok(Action configure) + public void AddRetry_Overloads_Ok(Action configure) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder.Invoking(b => configure(b)).Should().NotThrow(); } [MemberData(nameof(OverloadsDataGeneric))] [Theory] - public void AddRetry_GenericOverloads_Ok(Action> configure) + public void AddRetry_GenericOverloads_Ok(Action> configure) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); builder.Invoking(b => configure(b)).Should().NotThrow(); } @@ -60,7 +60,7 @@ public void AddRetry_GenericOverloads_Ok(Action> [Fact] public void AddRetry_DefaultOptions_Ok() { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); var options = new RetryStrategyOptions { ShouldHandle = _ => PredicateResult.True }; builder.AddRetry(options); @@ -68,7 +68,7 @@ public void AddRetry_DefaultOptions_Ok() AssertStrategy(builder, options.BackoffType, options.RetryCount, options.BaseDelay); } - private static void AssertStrategy(ResilienceStrategyBuilder builder, RetryBackoffType type, int retries, TimeSpan delay, Action>? assert = null) + private static void AssertStrategy(CompositeStrategyBuilder builder, RetryBackoffType type, int retries, TimeSpan delay, Action>? assert = null) { var strategy = (RetryResilienceStrategy)builder.Build(); @@ -79,7 +79,7 @@ private static void AssertStrategy(ResilienceStrategyBuilder builder, RetryBacko assert?.Invoke(strategy); } - private static void AssertStrategy(ResilienceStrategyBuilder builder, RetryBackoffType type, int retries, TimeSpan delay, Action>? assert = null) + private static void AssertStrategy(CompositeStrategyBuilder builder, RetryBackoffType type, int retries, TimeSpan delay, Action>? assert = null) { var strategy = (RetryResilienceStrategy)builder.Build().Strategy; @@ -93,12 +93,12 @@ private static void AssertStrategy(ResilienceStrategyBuilder builder, Retr [Fact] public void AddRetry_InvalidOptions_Throws() { - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .Invoking(b => b.AddRetry(new RetryStrategyOptions { ShouldHandle = null! })) .Should() .Throw(); - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .Invoking(b => b.AddRetry(new RetryStrategyOptions { ShouldHandle = null! })) .Should() .Throw(); @@ -125,7 +125,7 @@ private static TimeSpan GetAggregatedDelay(RetryStrategyOptions options) { var aggregatedDelay = TimeSpan.Zero; - var strategy = new ResilienceStrategyBuilder { Randomizer = () => 1.0 }.AddRetry(new() + var strategy = new CompositeStrategyBuilder { Randomizer = () => 1.0 }.AddRetry(new() { RetryCount = options.RetryCount, BaseDelay = options.BaseDelay, diff --git a/test/Polly.Core.Tests/Timeout/TimeoutResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.Core.Tests/Timeout/TimeoutCompositeStrategyBuilderExtensionsTests.cs similarity index 75% rename from test/Polly.Core.Tests/Timeout/TimeoutResilienceStrategyBuilderExtensionsTests.cs rename to test/Polly.Core.Tests/Timeout/TimeoutCompositeStrategyBuilderExtensionsTests.cs index 786517af422..c913b9b2129 100644 --- a/test/Polly.Core.Tests/Timeout/TimeoutResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.Core.Tests/Timeout/TimeoutCompositeStrategyBuilderExtensionsTests.cs @@ -3,7 +3,7 @@ namespace Polly.Core.Tests.Timeout; -public class TimeoutResilienceStrategyBuilderExtensionsTests +public class TimeoutCompositeStrategyBuilderExtensionsTests { public static IEnumerable AddTimeout_Ok_Data() { @@ -11,7 +11,7 @@ public static IEnumerable AddTimeout_Ok_Data() yield return new object[] { timeout, - (ResilienceStrategyBuilder builder) => { builder.AddTimeout(timeout); }, + (CompositeStrategyBuilder builder) => { builder.AddTimeout(timeout); }, (TimeoutResilienceStrategy strategy) => { GetTimeout(strategy).Should().Be(timeout); } }; } @@ -20,16 +20,16 @@ public static IEnumerable AddTimeout_Ok_Data() [Theory] public void AddTimeout_InvalidTimeout_EnsureValidated(TimeSpan timeout) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); Assert.Throws(() => builder.AddTimeout(timeout)); } [MemberData(nameof(AddTimeout_Ok_Data))] [Theory] - internal void AddTimeout_Ok(TimeSpan timeout, Action> configure, Action assert) + internal void AddTimeout_Ok(TimeSpan timeout, Action> configure, Action assert) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); configure(builder); var strategy = builder.Build().Strategy.Should().BeOfType().Subject; assert(strategy); @@ -40,7 +40,7 @@ internal void AddTimeout_Ok(TimeSpan timeout, Action(); } @@ -48,7 +48,7 @@ public void AddTimeout_Options_Ok() [Fact] public void AddTimeout_InvalidOptions_Throws() { - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .Invoking(b => b.AddTimeout(new TimeoutStrategyOptions { Timeout = TimeSpan.Zero })) .Should() .Throw(); diff --git a/test/Polly.Core.Tests/Utils/ResilienceStrategyPipelineTests.cs b/test/Polly.Core.Tests/Utils/CompositeResilienceStrategyTests.cs similarity index 64% rename from test/Polly.Core.Tests/Utils/ResilienceStrategyPipelineTests.cs rename to test/Polly.Core.Tests/Utils/CompositeResilienceStrategyTests.cs index 01ccadf21d1..ac1c16d80a3 100644 --- a/test/Polly.Core.Tests/Utils/ResilienceStrategyPipelineTests.cs +++ b/test/Polly.Core.Tests/Utils/CompositeResilienceStrategyTests.cs @@ -2,15 +2,15 @@ namespace Polly.Core.Tests.Utils; -public class ResilienceStrategyPipelineTests +public class CompositeResilienceStrategyTests { [Fact] - public void CreatePipeline_ArgValidation() + public void Create_ArgValidation() { - Assert.Throws(() => ResilienceStrategyPipeline.CreatePipeline(null!)); - Assert.Throws(() => ResilienceStrategyPipeline.CreatePipeline(Array.Empty())); - Assert.Throws(() => ResilienceStrategyPipeline.CreatePipeline(new ResilienceStrategy[] { new TestResilienceStrategy() })); - Assert.Throws(() => ResilienceStrategyPipeline.CreatePipeline(new ResilienceStrategy[] + Assert.Throws(() => CompositeResilienceStrategy.Create(null!)); + Assert.Throws(() => CompositeResilienceStrategy.Create(Array.Empty())); + Assert.Throws(() => CompositeResilienceStrategy.Create(new ResilienceStrategy[] { new TestResilienceStrategy() })); + Assert.Throws(() => CompositeResilienceStrategy.Create(new ResilienceStrategy[] { NullResilienceStrategy.Instance, NullResilienceStrategy.Instance @@ -18,7 +18,7 @@ public void CreatePipeline_ArgValidation() } [Fact] - public void CreatePipeline_EnsureOriginalStrategiesPreserved() + public void Create_EnsureOriginalStrategiesPreserved() { var strategies = new ResilienceStrategy[] { @@ -27,7 +27,7 @@ public void CreatePipeline_EnsureOriginalStrategiesPreserved() new TestResilienceStrategy(), }; - var pipeline = ResilienceStrategyPipeline.CreatePipeline(strategies); + var pipeline = CompositeResilienceStrategy.Create(strategies); for (var i = 0; i < strategies.Length; i++) { @@ -38,7 +38,7 @@ public void CreatePipeline_EnsureOriginalStrategiesPreserved() } [Fact] - public async Task CreatePipeline_EnsureExceptionsNotWrapped() + public async Task Create_EnsureExceptionsNotWrapped() { var strategies = new ResilienceStrategy[] { @@ -46,7 +46,7 @@ public async Task CreatePipeline_EnsureExceptionsNotWrapped() new Strategy(), }; - var pipeline = ResilienceStrategyPipeline.CreatePipeline(strategies); + var pipeline = CompositeResilienceStrategy.Create(strategies); await pipeline .Invoking(p => p.ExecuteCore((_, _) => Outcome.FromResultAsTask(10), ResilienceContextPool.Shared.Get(), "state").AsTask()) .Should() @@ -54,7 +54,7 @@ await pipeline } [Fact] - public void CreatePipeline_EnsurePipelineReusableAcrossDifferentPipelines() + public void Create_EnsurePipelineReusableAcrossDifferentPipelines() { var strategies = new ResilienceStrategy[] { @@ -63,17 +63,17 @@ public void CreatePipeline_EnsurePipelineReusableAcrossDifferentPipelines() new TestResilienceStrategy(), }; - var pipeline = ResilienceStrategyPipeline.CreatePipeline(strategies); + var pipeline = CompositeResilienceStrategy.Create(strategies); - ResilienceStrategyPipeline.CreatePipeline(new ResilienceStrategy[] { NullResilienceStrategy.Instance, pipeline }); + CompositeResilienceStrategy.Create(new ResilienceStrategy[] { NullResilienceStrategy.Instance, pipeline }); - this.Invoking(_ => ResilienceStrategyPipeline.CreatePipeline(new ResilienceStrategy[] { NullResilienceStrategy.Instance, pipeline })) + this.Invoking(_ => CompositeResilienceStrategy.Create(new ResilienceStrategy[] { NullResilienceStrategy.Instance, pipeline })) .Should() .NotThrow(); } [Fact] - public async Task CreatePipeline_Cancelled_EnsureNoExecution() + public async Task Create_Cancelled_EnsureNoExecution() { using var cancellation = new CancellationTokenSource(); cancellation.Cancel(); @@ -83,7 +83,7 @@ public async Task CreatePipeline_Cancelled_EnsureNoExecution() new TestResilienceStrategy(), }; - var pipeline = ResilienceStrategyPipeline.CreatePipeline(strategies); + var pipeline = CompositeResilienceStrategy.Create(strategies); var context = ResilienceContextPool.Shared.Get(); context.CancellationToken = cancellation.Token; @@ -92,7 +92,7 @@ public async Task CreatePipeline_Cancelled_EnsureNoExecution() } [Fact] - public async Task CreatePipeline_CancelledLater_EnsureNoExecution() + public async Task Create_CancelledLater_EnsureNoExecution() { var executed = false; using var cancellation = new CancellationTokenSource(); @@ -102,7 +102,7 @@ public async Task CreatePipeline_CancelledLater_EnsureNoExecution() new TestResilienceStrategy(), }; - var pipeline = ResilienceStrategyPipeline.CreatePipeline(strategies); + var pipeline = CompositeResilienceStrategy.Create(strategies); var context = ResilienceContextPool.Shared.Get(); context.CancellationToken = cancellation.Token; diff --git a/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs b/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs index 8166eac0d1c..52e42c7eb97 100644 --- a/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs +++ b/test/Polly.Extensions.Tests/DependencyInjection/PollyServiceCollectionExtensionTests.cs @@ -26,18 +26,18 @@ public void AddResilienceStrategy_ArgValidation() _services = new ServiceCollection(); Assert.Throws(() => _services.AddResilienceStrategy( Key, - (Action>)null!)); + (Action>)null!)); Assert.Throws(() => _services.AddResilienceStrategy( Key, - (Action, AddResilienceStrategyContext>)null!)); + (Action, AddResilienceStrategyContext>)null!)); Assert.Throws(() => _services.AddResilienceStrategy( Key, - (Action)null!)); + (Action)null!)); Assert.Throws(() => _services.AddResilienceStrategy( Key, - (Action>)null!)); + (Action>)null!)); } [InlineData(true)] @@ -56,10 +56,10 @@ public void AddResilienceStrategy_EnsureRegisteredServices(bool generic) var serviceProvider = _services.BuildServiceProvider(); - serviceProvider.GetServices().Should().NotBeNull(); + serviceProvider.GetServices().Should().NotBeNull(); serviceProvider.GetServices>().Should().NotBeNull(); serviceProvider.GetServices>().Should().NotBeNull(); - serviceProvider.GetServices().Should().NotBeSameAs(serviceProvider.GetServices()); + serviceProvider.GetServices().Should().NotBeSameAs(serviceProvider.GetServices()); } [Fact] @@ -161,7 +161,7 @@ public void AddResilienceStrategy_EnsureTelemetryEnabled(bool hasLogging) } [Fact] - public void AddResilienceStrategy_EnsureResilienceStrategyBuilderResolvedCorrectly() + public void AddResilienceStrategy_EnsureCompositeStrategyBuilderResolvedCorrectly() { var asserted = false; var key = new ResiliencePropertyKey("A"); @@ -261,7 +261,7 @@ public void AddResilienceStrategyRegistry_Ok() provider.GetRequiredService>().Should().NotBeNull(); provider.GetRequiredService>().Should().NotBeNull(); - provider.GetRequiredService().DiagnosticSource.Should().NotBeNull(); + provider.GetRequiredService().DiagnosticSource.Should().NotBeNull(); } [Fact] @@ -276,7 +276,7 @@ public void AddResilienceStrategyRegistry_ConfigureCallback_Ok() provider.GetRequiredService>>().Value.InstanceNameFormatter.Should().Be(formatter); } - private void AddResilienceStrategy(string key, Action? onBuilding = null) + private void AddResilienceStrategy(string key, Action? onBuilding = null) { _services.AddResilienceStrategy(key, builder => { @@ -288,7 +288,7 @@ private void AddResilienceStrategy(string key, Action(string key, Action? onBuilding = null) + private void AddResilienceStrategy(string key, Action? onBuilding = null) { _services.AddResilienceStrategy(key, builder => { diff --git a/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.Extensions.Tests/Telemetry/TelemetryCompositeStrategyBuilderExtensionsTests.cs similarity index 91% rename from test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs rename to test/Polly.Extensions.Tests/Telemetry/TelemetryCompositeStrategyBuilderExtensionsTests.cs index a72df5750ed..2e4c76a7ac9 100644 --- a/test/Polly.Extensions.Tests/Telemetry/TelemetryResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.Extensions.Tests/Telemetry/TelemetryCompositeStrategyBuilderExtensionsTests.cs @@ -4,9 +4,9 @@ namespace Polly.Extensions.Tests.Telemetry; -public class TelemetryResilienceStrategyBuilderExtensionsTests +public class TelemetryCompositeStrategyBuilderExtensionsTests { - private readonly ResilienceStrategyBuilder _builder = new(); + private readonly CompositeStrategyBuilder _builder = new(); [Fact] public void ConfigureTelemetry_EnsureDiagnosticSourceUpdated() diff --git a/test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyBuilderExtensionsTests.cs b/test/Polly.RateLimiting.Tests/RateLimiterCompositeStrategyBuilderExtensionsTests.cs similarity index 79% rename from test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyBuilderExtensionsTests.cs rename to test/Polly.RateLimiting.Tests/RateLimiterCompositeStrategyBuilderExtensionsTests.cs index 0b5aace3e86..10e36ecf422 100644 --- a/test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyBuilderExtensionsTests.cs +++ b/test/Polly.RateLimiting.Tests/RateLimiterCompositeStrategyBuilderExtensionsTests.cs @@ -4,9 +4,9 @@ namespace Polly.RateLimiting.Tests; -public class RateLimiterResilienceStrategyBuilderExtensionsTests +public class RateLimiterCompositeStrategyBuilderExtensionsTests { - public static readonly TheoryData>> Data = new() + public static readonly TheoryData>> Data = new() { builder => { @@ -34,9 +34,9 @@ public class RateLimiterResilienceStrategyBuilderExtensionsTests [MemberData(nameof(Data))] [Theory(Skip = "https://github.com/stryker-mutator/stryker-net/issues/2144")] - public void AddRateLimiter_Extensions_Ok(Action> configure) + public void AddRateLimiter_Extensions_Ok(Action> configure) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); configure(builder); @@ -48,7 +48,7 @@ public void AddConcurrencyLimiter_InvalidOptions_Throws() { Assert.Throws(() => { - return new ResilienceStrategyBuilder().AddConcurrencyLimiter(new ConcurrencyLimiterOptions + return new CompositeStrategyBuilder().AddConcurrencyLimiter(new ConcurrencyLimiterOptions { PermitLimit = -10, QueueLimit = -10 @@ -60,9 +60,9 @@ public void AddConcurrencyLimiter_InvalidOptions_Throws() [Fact] public void AddRateLimiter_AllExtensions_Ok() { - foreach (var configure in Data.Select(v => v[0]).Cast>>()) + foreach (var configure in Data.Select(v => v[0]).Cast>>()) { - var builder = new ResilienceStrategyBuilder(); + var builder = new CompositeStrategyBuilder(); configure(builder); @@ -79,7 +79,7 @@ public void AddRateLimiter_Ok() PermitLimit = 10 }); - new ResilienceStrategyBuilder() + new CompositeStrategyBuilder() .AddRateLimiter(new RateLimiterStrategyOptions { RateLimiter = ResilienceRateLimiter.Create(limiter) @@ -92,7 +92,7 @@ public void AddRateLimiter_Ok() [Fact] public void AddRateLimiter_InvalidOptions_Throws() { - new ResilienceStrategyBuilder().Invoking(b => b.AddRateLimiter(new RateLimiterStrategyOptions { DefaultRateLimiterOptions = null! })) + new CompositeStrategyBuilder().Invoking(b => b.AddRateLimiter(new RateLimiterStrategyOptions { DefaultRateLimiterOptions = null! })) .Should() .Throw() .WithMessage(""" @@ -106,7 +106,7 @@ The DefaultRateLimiterOptions field is required. [Fact] public void AddGenericRateLimiter_InvalidOptions_Throws() { - new ResilienceStrategyBuilder().Invoking(b => b.AddRateLimiter(new RateLimiterStrategyOptions { DefaultRateLimiterOptions = null! })) + new CompositeStrategyBuilder().Invoking(b => b.AddRateLimiter(new RateLimiterStrategyOptions { DefaultRateLimiterOptions = null! })) .Should() .Throw() .WithMessage(""" @@ -120,7 +120,7 @@ The DefaultRateLimiterOptions field is required. [Fact] public void AddRateLimiter_Options_Ok() { - var strategy = new ResilienceStrategyBuilder() + var strategy = new CompositeStrategyBuilder() .AddRateLimiter(new RateLimiterStrategyOptions { RateLimiter = ResilienceRateLimiter.Create(Mock.Of()) @@ -130,7 +130,7 @@ public void AddRateLimiter_Options_Ok() strategy.Should().BeOfType(); } - private static void AssertRateLimiter(ResilienceStrategyBuilder builder, bool hasEvents, Action? assertLimiter = null) + private static void AssertRateLimiter(CompositeStrategyBuilder builder, bool hasEvents, Action? assertLimiter = null) { var strategy = GetResilienceStrategy(builder.Build()); strategy.Limiter.Should().NotBeNull(); @@ -150,7 +150,7 @@ private static void AssertRateLimiter(ResilienceStrategyBuilder builder, bo assertLimiter?.Invoke(strategy.Limiter.Limiter!); } - private static void AssertConcurrencyLimiter(ResilienceStrategyBuilder builder, bool hasEvents) + private static void AssertConcurrencyLimiter(CompositeStrategyBuilder builder, bool hasEvents) { var strategy = GetResilienceStrategy(builder.Build()); strategy.Limiter.Limiter.Should().BeOfType(); diff --git a/test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyTests.cs b/test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyTests.cs index 42423ffd9fd..53763ece911 100644 --- a/test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyTests.cs +++ b/test/Polly.RateLimiting.Tests/RateLimiterResilienceStrategyTests.cs @@ -95,7 +95,7 @@ private void SetupLimiter(CancellationToken token) => _limiter private RateLimiterResilienceStrategy Create() { - var builder = new ResilienceStrategyBuilder + var builder = new CompositeStrategyBuilder { DiagnosticSource = _diagnosticSource.Object }; diff --git a/test/Polly.Specs/ResilienceStrategyConversionExtensionsTests.cs b/test/Polly.Specs/ResilienceStrategyConversionExtensionsTests.cs index 5eacbba7d95..685acee397a 100644 --- a/test/Polly.Specs/ResilienceStrategyConversionExtensionsTests.cs +++ b/test/Polly.Specs/ResilienceStrategyConversionExtensionsTests.cs @@ -35,7 +35,7 @@ public ResilienceStrategyConversionExtensionsTests() } }; - _genericStrategy = new ResilienceStrategyBuilder() + _genericStrategy = new CompositeStrategyBuilder() .AddStrategy(_strategy) .Build(); } @@ -158,7 +158,7 @@ public async Task AsAsyncPolicy_Result_Ok() [Fact] public void RetryStrategy_AsSyncPolicy_Ok() { - var policy = new ResilienceStrategyBuilder() + var policy = new CompositeStrategyBuilder() .AddRetry(new RetryStrategyOptions { ShouldHandle = _ => PredicateResult.True, diff --git a/test/Polly.Testing.Tests/ResilienceStrategyExtensionsTests.cs b/test/Polly.Testing.Tests/ResilienceStrategyExtensionsTests.cs index 48a4a6692cc..cdd589871e3 100644 --- a/test/Polly.Testing.Tests/ResilienceStrategyExtensionsTests.cs +++ b/test/Polly.Testing.Tests/ResilienceStrategyExtensionsTests.cs @@ -17,7 +17,7 @@ public class ResilienceStrategyExtensionsTests public void GetInnerStrategies_Ok() { // arrange - var strategy = new ResilienceStrategyBuilder() + var strategy = new CompositeStrategyBuilder() .AddFallback(new() { FallbackAction = _ => Outcome.FromResultAsTask("dummy"), @@ -56,7 +56,7 @@ public void GetInnerStrategies_Ok() public void GetInnerStrategies_SingleStrategy_Ok() { // arrange - var strategy = new ResilienceStrategyBuilder() + var strategy = new CompositeStrategyBuilder() .AddTimeout(TimeSpan.FromSeconds(1)) .Build();