CompositeStrategyBuilderExtensions
Extensions for CompositeStrategyBuilderBase.
using Polly.Utils;
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
namespace Polly
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public static class CompositeStrategyBuilderExtensions
{
[System.Runtime.CompilerServices.NullableContext(0)]
internal sealed class EmptyOptions : ResilienceStrategyOptions
{
[System.Runtime.CompilerServices.Nullable(1)]
public static readonly EmptyOptions Instance = new EmptyOptions();
}
[System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "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<[System.Runtime.CompilerServices.Nullable(0)] TBuilder>(this TBuilder builder, ResilienceStrategy strategy) where TBuilder : CompositeStrategyBuilderBase
{
Guard.NotNull(builder, "builder");
Guard.NotNull(strategy, "strategy");
return builder.AddStrategy((StrategyBuilderContext _) => strategy, EmptyOptions.Instance);
}
public static CompositeStrategyBuilder<TResult> AddStrategy<[System.Runtime.CompilerServices.Nullable(2)] TResult>(this CompositeStrategyBuilder<TResult> builder, ResilienceStrategy<TResult> strategy)
{
Guard.NotNull(builder, "builder");
Guard.NotNull(strategy, "strategy");
return builder.AddStrategy(strategy.Strategy);
}
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This call validates the options using the data annotations attributes.\r\nMake sure that the options are included by adding the '[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(OptionsType))]' attribute to the calling method.")]
public static TBuilder AddStrategy<[System.Runtime.CompilerServices.Nullable(0)] TBuilder>(this TBuilder builder, Func<StrategyBuilderContext, ResilienceStrategy> factory, ResilienceStrategyOptions options) where TBuilder : CompositeStrategyBuilderBase
{
Guard.NotNull(builder, "builder");
Guard.NotNull(factory, "factory");
Guard.NotNull(options, "options");
builder.AddStrategyCore(factory, options);
return builder;
}
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This call validates the options using the data annotations attributes.\r\nMake sure that the options are included by adding the '[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(OptionsType))]' attribute to the calling method.")]
public static CompositeStrategyBuilder AddStrategy(this CompositeStrategyBuilder builder, Func<StrategyBuilderContext, ReactiveResilienceStrategy<object>> factory, ResilienceStrategyOptions options)
{
Guard.NotNull(builder, "builder");
Guard.NotNull(factory, "factory");
Guard.NotNull(options, "options");
builder.AddStrategyCore((StrategyBuilderContext context) => new ReactiveResilienceStrategyBridge<object>(factory(context)), options);
return builder;
}
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("This call validates the options using the data annotations attributes.\r\nMake sure that the options are included by adding the '[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(OptionsType))]' attribute to the calling method.")]
public static CompositeStrategyBuilder<TResult> AddStrategy<[System.Runtime.CompilerServices.Nullable(2)] TResult>(this CompositeStrategyBuilder<TResult> builder, Func<StrategyBuilderContext, ReactiveResilienceStrategy<TResult>> factory, ResilienceStrategyOptions options)
{
Guard.NotNull(builder, "builder");
Guard.NotNull(factory, "factory");
Guard.NotNull(options, "options");
builder.AddStrategyCore((StrategyBuilderContext context) => new ReactiveResilienceStrategyBridge<TResult>(factory(context)), options);
return builder;
}
}
}