Skip to content

Commit

Permalink
Rename ResilienceStrategyBuilder to CompositeStrategyBuilder (#1448)
Browse files Browse the repository at this point in the history
  • Loading branch information
martintmk authored Jul 28, 2023
1 parent 6d0d8ef commit f8bea05
Show file tree
Hide file tree
Showing 51 changed files with 321 additions and 321 deletions.
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/CreationBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static void Fallback_V7()
[Benchmark]
public static void Fallback_V8()
{
new ResilienceStrategyBuilder<string>()
new CompositeStrategyBuilder<string>()
.AddFallback(new()
{
FallbackAction = _ => Outcome.FromResultAsTask("fallback")
Expand Down
4 changes: 2 additions & 2 deletions bench/Polly.Core.Benchmarks/TelemetryBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TelemetryBenchmark
[GlobalSetup]
public void Prepare()
{
_strategy = Build(new ResilienceStrategyBuilder());
_strategy = Build(new CompositeStrategyBuilder());

if (Telemetry)
{
Expand All @@ -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());

Expand Down
2 changes: 1 addition & 1 deletion bench/Polly.Core.Benchmarks/Utils/Helper.CircuitBreaker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ internal static partial class Helper

public static ResilienceStrategy CreateNonGenericStrategyPipeline()
{
return new ResilienceStrategyBuilder()
return new CompositeStrategyBuilder()
.AddConcurrencyLimiter(new ConcurrencyLimiterOptions
{
QueueLimit = 10,
Expand Down
4 changes: 2 additions & 2 deletions bench/Polly.Core.Benchmarks/Utils/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public static async ValueTask ExecuteAsync(this object obj, PollyVersion version
throw new NotSupportedException();
}

private static ResilienceStrategy<string> CreateStrategy(Action<ResilienceStrategyBuilder<string>> configure)
private static ResilienceStrategy<string> CreateStrategy(Action<CompositeStrategyBuilder<string>> configure)
{
var builder = new ResilienceStrategyBuilder<string>();
var builder = new CompositeStrategyBuilder<string>();
configure(builder);
return builder.Build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Polly;

/// <summary>
/// Circuit breaker strategy extensions for <see cref="ResilienceStrategyBuilder"/>.
/// Circuit breaker strategy extensions for <see cref="CompositeStrategyBuilder"/>.
/// </summary>
public static class CircuitBreakerResilienceStrategyBuilderExtensions
public static class CircuitBreakerCompositeStrategyBuilderExtensions
{
/// <summary>
/// Add circuit breaker strategy to the builder.
Expand All @@ -24,7 +24,7 @@ public static class CircuitBreakerResilienceStrategyBuilderExtensions
/// </remarks>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> are invalid.</exception>
public static ResilienceStrategyBuilder AddCircuitBreaker(this ResilienceStrategyBuilder builder, CircuitBreakerStrategyOptions options)
public static CompositeStrategyBuilder AddCircuitBreaker(this CompositeStrategyBuilder builder, CircuitBreakerStrategyOptions options)
{
Guard.NotNull(builder);
Guard.NotNull(options);
Expand All @@ -47,7 +47,7 @@ public static ResilienceStrategyBuilder AddCircuitBreaker(this ResilienceStrateg
/// </remarks>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> are invalid.</exception>
public static ResilienceStrategyBuilder<TResult> AddCircuitBreaker<TResult>(this ResilienceStrategyBuilder<TResult> builder, CircuitBreakerStrategyOptions<TResult> options)
public static CompositeStrategyBuilder<TResult> AddCircuitBreaker<TResult>(this CompositeStrategyBuilder<TResult> builder, CircuitBreakerStrategyOptions<TResult> options)
{
Guard.NotNull(builder);
Guard.NotNull(options);
Expand All @@ -60,7 +60,7 @@ public static ResilienceStrategyBuilder<TResult> AddCircuitBreaker<TResult>(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<TBuilder, TResult>(this TBuilder builder, CircuitBreakerStrategyOptions<TResult> options)
where TBuilder : ResilienceStrategyBuilderBase
where TBuilder : CompositeStrategyBuilderBase
{
return builder.AddStrategy(
context =>
Expand All @@ -76,7 +76,7 @@ private static TBuilder AddCircuitBreakerCore<TBuilder, TResult>(this TBuilder b
}

internal static CircuitBreakerResilienceStrategy<TResult> CreateStrategy<TResult, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TOptions>(
ResilienceStrategyBuilderContext context,
StrategyBuilderContext context,
CircuitBreakerStrategyOptions<TResult> options,
CircuitBehavior behavior)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal void Initialize(Func<CircuitState> circuitStateProvider, Func<Outcome<o
/// </summary>
/// <remarks>
/// The initialization happens when the circuit-breaker strategy is attached to this class.
/// This happens when the final strategy is created by the <see cref="ResilienceStrategyBuilder.Build"/> call.
/// This happens when the final strategy is created by the <see cref="CompositeStrategyBuilder.Build"/> call.
/// </remarks>
internal bool IsInitialized => _circuitStateProvider != null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace Polly;
/// </summary>
/// <typeparam name="TResult">The type of result to handle.</typeparam>
/// <remarks>
/// 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 <see cref="ResilienceStrategy{TResult}"/> created by the <see cref="Build"/> call will execute the strategies in the same order they were added to the builder.
/// The order of the strategies is important.
/// </remarks>
public sealed class ResilienceStrategyBuilder<TResult> : ResilienceStrategyBuilderBase
public sealed class CompositeStrategyBuilder<TResult> : CompositeStrategyBuilderBase
{
/// <summary>
/// Initializes a new instance of the <see cref="ResilienceStrategyBuilder{TResult}"/> class.
/// Initializes a new instance of the <see cref="CompositeStrategyBuilder{TResult}"/> class.
/// </summary>
public ResilienceStrategyBuilder()
public CompositeStrategyBuilder()
{
}

internal ResilienceStrategyBuilder(ResilienceStrategyBuilderBase other)
internal CompositeStrategyBuilder(CompositeStrategyBuilderBase other)
: base(other)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ namespace Polly;
/// A builder that is used to create an instance of <see cref="ResilienceStrategy"/>.
/// </summary>
/// <remarks>
/// 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 <see cref="ResilienceStrategy"/> created by the <see cref="Build"/> call will execute the strategies in the same order they were added to the builder.
/// The order of the strategies is important.
/// </remarks>
public sealed class ResilienceStrategyBuilder : ResilienceStrategyBuilderBase
public sealed class CompositeStrategyBuilder : CompositeStrategyBuilderBase
{
/// <summary>
/// Builds the resilience strategy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ namespace Polly;
/// A builder that is used to create an instance of <see cref="ResilienceStrategy"/>.
/// </summary>
/// <remarks>
/// 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 <see cref="ResilienceStrategy"/> executes the strategies in the same order they were added to the builder.
/// The order of the strategies is important.
/// </remarks>
public abstract class ResilienceStrategyBuilderBase
public abstract class CompositeStrategyBuilderBase
{
private readonly List<Entry> _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;
Expand Down Expand Up @@ -121,7 +121,7 @@ private protected ResilienceStrategyBuilderBase(ResilienceStrategyBuilderBase ot
public Action<ResilienceValidationContext> Validator { get; private protected set; } = ValidationHelper.ValidateObject;

[RequiresUnreferencedCode(Constants.OptionsValidation)]
internal void AddStrategyCore(Func<ResilienceStrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options)
internal void AddStrategyCore(Func<StrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options)
{
Guard.NotNull(factory);
Guard.NotNull(options);
Expand All @@ -138,7 +138,7 @@ internal void AddStrategyCore(Func<ResilienceStrategyBuilderContext, ResilienceS

internal ResilienceStrategy BuildStrategy()
{
Validator(new(this, $"The '{nameof(ResilienceStrategyBuilder)}' configuration is invalid."));
Validator(new(this, $"The '{nameof(CompositeStrategyBuilder)}' configuration is invalid."));

_used = true;

Expand All @@ -155,12 +155,12 @@ internal ResilienceStrategy BuildStrategy()
return strategies[0];
}

return ResilienceStrategyPipeline.CreatePipeline(strategies);
return CompositeResilienceStrategy.Create(strategies);
}

private ResilienceStrategy CreateResilienceStrategy(Entry entry)
{
var context = new ResilienceStrategyBuilderContext(
var context = new StrategyBuilderContext(
builderName: Name,
builderInstanceName: InstanceName,
builderProperties: Properties,
Expand All @@ -174,5 +174,5 @@ private ResilienceStrategy CreateResilienceStrategy(Entry entry)
return strategy;
}

private sealed record Entry(Func<ResilienceStrategyBuilderContext, ResilienceStrategy> Factory, ResilienceStrategyOptions Options);
private sealed record Entry(Func<StrategyBuilderContext, ResilienceStrategy> Factory, ResilienceStrategyOptions Options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace Polly;

/// <summary>
/// Extensions for <see cref="ResilienceStrategyBuilderBase"/>.
/// Extensions for <see cref="CompositeStrategyBuilderBase"/>.
/// </summary>
public static class ResilienceStrategyBuilderExtensions
public static class CompositeStrategyBuilderExtensions
{
/// <summary>
/// Adds an already created strategy instance to the builder.
Expand All @@ -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<TBuilder>(this TBuilder builder, ResilienceStrategy strategy)
where TBuilder : ResilienceStrategyBuilderBase
where TBuilder : CompositeStrategyBuilderBase
{
Guard.NotNull(builder);
Guard.NotNull(strategy);
Expand All @@ -39,7 +39,7 @@ public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, ResilienceSt
/// <returns>The same builder instance.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="strategy"/> is null.</exception>
/// <exception cref="InvalidOperationException">Thrown when this builder was already used to create a strategy. The builder cannot be modified after it has been used.</exception>
public static ResilienceStrategyBuilder<TResult> AddStrategy<TResult>(this ResilienceStrategyBuilder<TResult> builder, ResilienceStrategy<TResult> strategy)
public static CompositeStrategyBuilder<TResult> AddStrategy<TResult>(this CompositeStrategyBuilder<TResult> builder, ResilienceStrategy<TResult> strategy)
{
Guard.NotNull(builder);
Guard.NotNull(strategy);
Expand All @@ -59,8 +59,8 @@ public static ResilienceStrategyBuilder<TResult> AddStrategy<TResult>(this Resil
/// <exception cref="InvalidOperationException">Thrown when this builder was already used to create a strategy. The builder cannot be modified after it has been used.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> is invalid.</exception>
[RequiresUnreferencedCode(Constants.OptionsValidation)]
public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, Func<ResilienceStrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options)
where TBuilder : ResilienceStrategyBuilderBase
public static TBuilder AddStrategy<TBuilder>(this TBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options)
where TBuilder : CompositeStrategyBuilderBase
{
Guard.NotNull(builder);
Guard.NotNull(factory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Polly;

/// <summary>
/// Provides extension methods for configuring fallback resilience strategies for <see cref="ResilienceStrategyBuilder"/>.
/// Provides extension methods for configuring fallback resilience strategies for <see cref="CompositeStrategyBuilder"/>.
/// </summary>
public static class FallbackResilienceStrategyBuilderExtensions
public static class FallbackCompositeStrategyBuilderExtensions
{
/// <summary>
/// Adds a fallback resilience strategy with the provided options to the builder.
Expand All @@ -18,7 +18,7 @@ public static class FallbackResilienceStrategyBuilderExtensions
/// <returns>The builder instance with the fallback strategy added.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> are invalid.</exception>
public static ResilienceStrategyBuilder<TResult> AddFallback<TResult>(this ResilienceStrategyBuilder<TResult> builder, FallbackStrategyOptions<TResult> options)
public static CompositeStrategyBuilder<TResult> AddFallback<TResult>(this CompositeStrategyBuilder<TResult> builder, FallbackStrategyOptions<TResult> options)
{
Guard.NotNull(builder);
Guard.NotNull(options);
Expand All @@ -35,7 +35,7 @@ public static ResilienceStrategyBuilder<TResult> AddFallback<TResult>(this Resil
/// <returns>The builder instance with the fallback strategy added.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> are invalid.</exception>
internal static ResilienceStrategyBuilder AddFallback(this ResilienceStrategyBuilder builder, FallbackStrategyOptions options)
internal static CompositeStrategyBuilder AddFallback(this CompositeStrategyBuilder builder, FallbackStrategyOptions options)
{
Guard.NotNull(builder);
Guard.NotNull(options);
Expand All @@ -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<TResult, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties)] TOptions>(
this ResilienceStrategyBuilderBase builder,
this CompositeStrategyBuilderBase builder,
FallbackStrategyOptions<TResult> options)
{
builder.AddStrategy(context =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Polly;

/// <summary>
/// Provides extension methods for configuring hedging resilience strategies for <see cref="ResilienceStrategyBuilder"/>.
/// Provides extension methods for configuring hedging resilience strategies for <see cref="CompositeStrategyBuilder"/>.
/// </summary>
public static class HedgingResilienceStrategyBuilderExtensions
public static class HedgingCompositeStrategyBuilderExtensions
{
/// <summary>
/// Adds a hedging resilience strategy with the provided options to the builder.
Expand All @@ -19,7 +19,7 @@ public static class HedgingResilienceStrategyBuilderExtensions
/// <returns>The builder instance with the hedging strategy added.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> are invalid.</exception>
public static ResilienceStrategyBuilder<TResult> AddHedging<TResult>(this ResilienceStrategyBuilder<TResult> builder, HedgingStrategyOptions<TResult> options)
public static CompositeStrategyBuilder<TResult> AddHedging<TResult>(this CompositeStrategyBuilder<TResult> builder, HedgingStrategyOptions<TResult> options)
{
Guard.NotNull(builder);
Guard.NotNull(options);
Expand All @@ -36,7 +36,7 @@ public static ResilienceStrategyBuilder<TResult> AddHedging<TResult>(this Resili
/// <returns>The builder instance with the hedging strategy added.</returns>
/// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="options"/> is <see langword="null"/>.</exception>
/// <exception cref="ValidationException">Thrown when <paramref name="options"/> are invalid.</exception>
internal static ResilienceStrategyBuilder AddHedging(this ResilienceStrategyBuilder builder, HedgingStrategyOptions options)
internal static CompositeStrategyBuilder AddHedging(this CompositeStrategyBuilder builder, HedgingStrategyOptions options)
{
Guard.NotNull(builder);
Guard.NotNull(options);
Expand All @@ -50,15 +50,15 @@ 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<TResult, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TOptions>(
this ResilienceStrategyBuilderBase builder,
this CompositeStrategyBuilderBase builder,
HedgingStrategyOptions<TResult> options)
{
builder.AddStrategy(context =>
{
var handler = new HedgingHandler<TResult>(
options.ShouldHandle!,
options.HedgingActionGenerator,
IsGeneric: builder is not ResilienceStrategyBuilder);
IsGeneric: builder is not CompositeStrategyBuilder);
return new HedgingResilienceStrategy<TResult>(
options.HedgingDelay,
Expand Down
Loading

0 comments on commit f8bea05

Please sign in to comment.