<PackageReference Include="Polly.Core" Version="8.5.0" />

ChaosFaultPipelineBuilderExtensions

Extension methods for adding chaos fault strategy to a ResiliencePipelineBuilder.
using Polly.Simmy.Fault; using Polly.Utils; using System; using System.Diagnostics.CodeAnalysis; using System.Runtime.CompilerServices; using System.Threading.Tasks; namespace Polly.Simmy { [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public static class ChaosFaultPipelineBuilderExtensions { public static TBuilder AddChaosFault<[System.Runtime.CompilerServices.Nullable(0)] TBuilder>(this TBuilder builder, double injectionRate, [System.Runtime.CompilerServices.Nullable(new byte[] { 1, 2 })] Func<Exception> faultGenerator) where TBuilder : ResiliencePipelineBuilderBase { Guard.NotNull(builder, "builder"); return builder.AddChaosFault(new ChaosFaultStrategyOptions { InjectionRate = injectionRate, FaultGenerator = (Func<FaultGeneratorArguments, ValueTask<Exception>>)((FaultGeneratorArguments _) => new ValueTask<Exception>(faultGenerator())) }); } [System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "All options members preserved.")] public static TBuilder AddChaosFault<[System.Runtime.CompilerServices.Nullable(0)] TBuilder>(this TBuilder builder, ChaosFaultStrategyOptions options) where TBuilder : ResiliencePipelineBuilderBase { Guard.NotNull(builder, "builder"); Guard.NotNull(options, "options"); return builder.AddStrategy((StrategyBuilderContext context) => new ChaosFaultStrategy(options, context.Telemetry), options); } } }