diff --git a/src/Polly.Core/Simmy/Behavior/BehaviorPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Behavior/BehaviorPipelineBuilderExtensions.cs
index c8ac539822..322c1d1524 100644
--- a/src/Polly.Core/Simmy/Behavior/BehaviorPipelineBuilderExtensions.cs
+++ b/src/Polly.Core/Simmy/Behavior/BehaviorPipelineBuilderExtensions.cs
@@ -14,20 +14,19 @@ internal static class BehaviorPipelineBuilderExtensions
///
/// The builder type.
/// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
/// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
/// The behavior to be injected.
/// The same builder instance.
/// Thrown when is .
/// Thrown when the options produced from the arguments are invalid.
- public static TBuilder AddChaosBehavior(this TBuilder builder, bool enabled, double injectionRate, Func behavior)
+ public static TBuilder AddChaosBehavior(this TBuilder builder, double injectionRate, Func behavior)
where TBuilder : ResiliencePipelineBuilderBase
{
Guard.NotNull(builder);
return builder.AddChaosBehavior(new BehaviorStrategyOptions
{
- Enabled = enabled,
+ Enabled = true,
InjectionRate = injectionRate,
BehaviorAction = (_) => behavior()
});
diff --git a/src/Polly.Core/Simmy/Fault/FaultChaosStrategy.cs b/src/Polly.Core/Simmy/Fault/FaultChaosStrategy.cs
new file mode 100644
index 0000000000..a394f05c23
--- /dev/null
+++ b/src/Polly.Core/Simmy/Fault/FaultChaosStrategy.cs
@@ -0,0 +1,60 @@
+using Polly.Telemetry;
+
+namespace Polly.Simmy.Fault;
+
+internal class FaultChaosStrategy : MonkeyStrategy
+{
+ private readonly ResilienceStrategyTelemetry _telemetry;
+
+ public FaultChaosStrategy(FaultStrategyOptions options, ResilienceStrategyTelemetry telemetry)
+ : base(options)
+ {
+ if (options.Fault is null && options.FaultGenerator is null)
+ {
+ throw new InvalidOperationException("Either Fault or FaultGenerator is required.");
+ }
+
+ _telemetry = telemetry;
+ Fault = options.Fault;
+ OnFaultInjected = options.OnFaultInjected;
+ FaultGenerator = options.FaultGenerator is not null ? options.FaultGenerator : (_) => new(options.Fault);
+ }
+
+ public Func? OnFaultInjected { get; }
+
+ public Func> FaultGenerator { get; }
+
+ public Exception? Fault { get; }
+
+ protected internal override async ValueTask> ExecuteCore(
+ Func>> callback,
+ ResilienceContext context,
+ TState state)
+ {
+ try
+ {
+ if (await ShouldInjectAsync(context).ConfigureAwait(context.ContinueOnCapturedContext))
+ {
+ var fault = await FaultGenerator(new(context)).ConfigureAwait(context.ContinueOnCapturedContext);
+ if (fault is not null)
+ {
+ var args = new OnFaultInjectedArguments(context, fault);
+ _telemetry.Report(new(ResilienceEventSeverity.Information, FaultConstants.OnFaultInjectedEvent), context, args);
+
+ if (OnFaultInjected is not null)
+ {
+ await OnFaultInjected(args).ConfigureAwait(context.ContinueOnCapturedContext);
+ }
+
+ return new Outcome(fault);
+ }
+ }
+
+ return await StrategyHelper.ExecuteCallbackSafeAsync(callback, context, state).ConfigureAwait(context.ContinueOnCapturedContext);
+ }
+ catch (OperationCanceledException e)
+ {
+ return new Outcome(e);
+ }
+ }
+}
diff --git a/src/Polly.Core/Simmy/Fault/FaultConstants.cs b/src/Polly.Core/Simmy/Fault/FaultConstants.cs
new file mode 100644
index 0000000000..1e8f325af5
--- /dev/null
+++ b/src/Polly.Core/Simmy/Fault/FaultConstants.cs
@@ -0,0 +1,6 @@
+namespace Polly.Simmy.Fault;
+
+internal static class FaultConstants
+{
+ public const string OnFaultInjectedEvent = "OnFaultInjectedEvent";
+}
diff --git a/src/Polly.Core/Simmy/Outcomes/FaultGeneratorArguments.cs b/src/Polly.Core/Simmy/Fault/FaultGeneratorArguments.cs
similarity index 95%
rename from src/Polly.Core/Simmy/Outcomes/FaultGeneratorArguments.cs
rename to src/Polly.Core/Simmy/Fault/FaultGeneratorArguments.cs
index 78fa6a35d6..6addf26ae5 100644
--- a/src/Polly.Core/Simmy/Outcomes/FaultGeneratorArguments.cs
+++ b/src/Polly.Core/Simmy/Fault/FaultGeneratorArguments.cs
@@ -1,4 +1,4 @@
-namespace Polly.Simmy.Outcomes;
+namespace Polly.Simmy.Fault;
#pragma warning disable CA1815 // Override equals and operator equals on value types
diff --git a/src/Polly.Core/Simmy/Fault/FaultPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Fault/FaultPipelineBuilderExtensions.cs
new file mode 100644
index 0000000000..3705c4cb28
--- /dev/null
+++ b/src/Polly.Core/Simmy/Fault/FaultPipelineBuilderExtensions.cs
@@ -0,0 +1,72 @@
+using System.Diagnostics.CodeAnalysis;
+using Polly.Simmy.Fault;
+
+namespace Polly.Simmy;
+
+///
+/// Extension methods for adding outcome to a .
+///
+internal static class FaultPipelineBuilderExtensions
+{
+ ///
+ /// Adds a fault chaos strategy to the builder.
+ ///
+ /// The builder instance.
+ /// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
+ /// The exception to inject.
+ /// The builder instance with the retry strategy added.
+ public static TBuilder AddChaosFault(this TBuilder builder, double injectionRate, Exception fault)
+ where TBuilder : ResiliencePipelineBuilderBase
+ {
+ builder.AddChaosFault(new FaultStrategyOptions
+ {
+ Enabled = true,
+ InjectionRate = injectionRate,
+ Fault = fault
+ });
+ return builder;
+ }
+
+ ///
+ /// Adds a fault chaos strategy to the builder.
+ ///
+ /// The builder instance.
+ /// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
+ /// The exception generator delegate.
+ /// The builder instance with the retry strategy added.
+ public static TBuilder AddChaosFault(this TBuilder builder, double injectionRate, Func faultGenerator)
+ where TBuilder : ResiliencePipelineBuilderBase
+ {
+ builder.AddChaosFault(new FaultStrategyOptions
+ {
+ Enabled = true,
+ InjectionRate = injectionRate,
+ FaultGenerator = (_) => new ValueTask(Task.FromResult(faultGenerator()))
+ });
+ return builder;
+ }
+
+ ///
+ /// Adds a fault chaos strategy to the builder.
+ ///
+ /// The builder type.
+ /// The builder instance.
+ /// The fault strategy options.
+ /// The builder instance with the retry strategy added.
+ [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(this TBuilder builder, FaultStrategyOptions options)
+ where TBuilder : ResiliencePipelineBuilderBase
+ {
+ Guard.NotNull(builder);
+ Guard.NotNull(options);
+
+ builder.AddStrategy(
+ context => new FaultChaosStrategy(options, context.Telemetry),
+ options);
+
+ return builder;
+ }
+}
diff --git a/src/Polly.Core/Simmy/Outcomes/FaultStrategyOptions.cs b/src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs
similarity index 97%
rename from src/Polly.Core/Simmy/Outcomes/FaultStrategyOptions.cs
rename to src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs
index eeb94f7eaa..1c8ca2d7a0 100644
--- a/src/Polly.Core/Simmy/Outcomes/FaultStrategyOptions.cs
+++ b/src/Polly.Core/Simmy/Fault/FaultStrategyOptions.cs
@@ -1,4 +1,4 @@
-namespace Polly.Simmy.Outcomes;
+namespace Polly.Simmy.Fault;
#pragma warning disable CS8618 // Required members are not initialized in constructor since this is a DTO, default value is null
diff --git a/src/Polly.Core/Simmy/Outcomes/OnFaultInjectedArguments.cs b/src/Polly.Core/Simmy/Fault/OnFaultInjectedArguments.cs
similarity index 96%
rename from src/Polly.Core/Simmy/Outcomes/OnFaultInjectedArguments.cs
rename to src/Polly.Core/Simmy/Fault/OnFaultInjectedArguments.cs
index 36e9287866..d883da412d 100644
--- a/src/Polly.Core/Simmy/Outcomes/OnFaultInjectedArguments.cs
+++ b/src/Polly.Core/Simmy/Fault/OnFaultInjectedArguments.cs
@@ -1,4 +1,4 @@
-namespace Polly.Simmy.Outcomes;
+namespace Polly.Simmy.Fault;
#pragma warning disable CA1815 // Override equals and operator equals on value types
diff --git a/src/Polly.Core/Simmy/Latency/LatencyPipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Latency/LatencyPipelineBuilderExtensions.cs
index f3321f6344..2fdc749ca0 100644
--- a/src/Polly.Core/Simmy/Latency/LatencyPipelineBuilderExtensions.cs
+++ b/src/Polly.Core/Simmy/Latency/LatencyPipelineBuilderExtensions.cs
@@ -14,20 +14,19 @@ internal static class LatencyPipelineBuilderExtensions
///
/// The builder type.
/// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
/// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
/// The delay value.
/// The same builder instance.
/// Thrown when is .
/// Thrown when the options produced from the arguments are invalid.
- public static TBuilder AddChaosLatency(this TBuilder builder, bool enabled, double injectionRate, TimeSpan latency)
+ public static TBuilder AddChaosLatency(this TBuilder builder, double injectionRate, TimeSpan latency)
where TBuilder : ResiliencePipelineBuilderBase
{
Guard.NotNull(builder);
return builder.AddChaosLatency(new LatencyStrategyOptions
{
- Enabled = enabled,
+ Enabled = true,
InjectionRate = injectionRate,
Latency = latency
});
diff --git a/src/Polly.Core/Simmy/Outcomes/OutcomeChaosStrategy.cs b/src/Polly.Core/Simmy/Outcomes/OutcomeChaosStrategy.cs
index 06a1322310..da5fd02b63 100644
--- a/src/Polly.Core/Simmy/Outcomes/OutcomeChaosStrategy.cs
+++ b/src/Polly.Core/Simmy/Outcomes/OutcomeChaosStrategy.cs
@@ -8,45 +8,17 @@ internal class OutcomeChaosStrategy : MonkeyStrategy
{
private readonly ResilienceStrategyTelemetry _telemetry;
- public OutcomeChaosStrategy(FaultStrategyOptions options, ResilienceStrategyTelemetry telemetry)
- : base(options)
- {
- if (options.Fault is null && options.FaultGenerator is null)
- {
- throw new InvalidOperationException("Either Fault or FaultGenerator is required.");
- }
-
- _telemetry = telemetry;
- Fault = options.Fault;
- OnFaultInjected = options.OnFaultInjected;
- FaultGenerator = options.FaultGenerator is not null ? options.FaultGenerator : (_) => new(options.Fault);
- }
-
public OutcomeChaosStrategy(OutcomeStrategyOptions options, ResilienceStrategyTelemetry telemetry)
: base(options)
{
- if (options.Outcome is null && options.OutcomeGenerator is null)
- {
- throw new InvalidOperationException("Either Outcome or OutcomeGenerator is required.");
- }
-
_telemetry = telemetry;
- Outcome = options.Outcome;
OnOutcomeInjected = options.OnOutcomeInjected;
- OutcomeGenerator = options.OutcomeGenerator is not null ? options.OutcomeGenerator : (_) => new(options.Outcome);
+ OutcomeGenerator = options.OutcomeGenerator;
}
public Func, ValueTask>? OnOutcomeInjected { get; }
- public Func? OnFaultInjected { get; }
-
- public Func?>>? OutcomeGenerator { get; }
-
- public Func>? FaultGenerator { get; }
-
- public Outcome? Outcome { get; }
-
- public Exception? Fault { get; }
+ public Func?>> OutcomeGenerator { get; }
protected internal override async ValueTask> ExecuteCore(Func>> callback, ResilienceContext context, TState state)
{
@@ -54,19 +26,16 @@ protected internal override async ValueTask> ExecuteCore(Func
{
if (await ShouldInjectAsync(context).ConfigureAwait(context.ContinueOnCapturedContext))
{
- if (FaultGenerator is not null)
- {
- var fault = await InjectFault(context).ConfigureAwait(context.ContinueOnCapturedContext);
- if (fault is not null)
- {
- return new Outcome(fault);
- }
- }
- else if (OutcomeGenerator is not null)
+ var outcome = await OutcomeGenerator(new(context)).ConfigureAwait(context.ContinueOnCapturedContext);
+ var args = new OnOutcomeInjectedArguments(context, outcome.Value);
+ _telemetry.Report(new(ResilienceEventSeverity.Information, OutcomeConstants.OnOutcomeInjectedEvent), context, args);
+
+ if (OnOutcomeInjected is not null)
{
- var outcome = await InjectOutcome(context).ConfigureAwait(context.ContinueOnCapturedContext);
- return new Outcome(outcome.Value.Result);
+ await OnOutcomeInjected(args).ConfigureAwait(context.ContinueOnCapturedContext);
}
+
+ return new Outcome(outcome.Value.Result);
}
return await StrategyHelper.ExecuteCallbackSafeAsync(callback, context, state).ConfigureAwait(context.ContinueOnCapturedContext);
@@ -76,37 +45,4 @@ protected internal override async ValueTask> ExecuteCore(Func
return new Outcome(e);
}
}
-
- private async ValueTask?> InjectOutcome(ResilienceContext context)
- {
- var outcome = await OutcomeGenerator!(new(context)).ConfigureAwait(context.ContinueOnCapturedContext);
- var args = new OnOutcomeInjectedArguments(context, outcome.Value);
- _telemetry.Report(new(ResilienceEventSeverity.Information, OutcomeConstants.OnOutcomeInjectedEvent), context, args);
-
- if (OnOutcomeInjected is not null)
- {
- await OnOutcomeInjected(args).ConfigureAwait(context.ContinueOnCapturedContext);
- }
-
- return outcome;
- }
-
- private async ValueTask InjectFault(ResilienceContext context)
- {
- var fault = await FaultGenerator!(new(context)).ConfigureAwait(context.ContinueOnCapturedContext);
- if (fault is null)
- {
- return null;
- }
-
- var args = new OnFaultInjectedArguments(context, fault);
- _telemetry.Report(new(ResilienceEventSeverity.Information, OutcomeConstants.OnFaultInjectedEvent), context, args);
-
- if (OnFaultInjected is not null)
- {
- await OnFaultInjected(args).ConfigureAwait(context.ContinueOnCapturedContext);
- }
-
- return fault;
- }
}
diff --git a/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs b/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs
index c3fbf42e8d..d061a0579f 100644
--- a/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs
+++ b/src/Polly.Core/Simmy/Outcomes/OutcomeConstants.cs
@@ -3,6 +3,4 @@
internal static class OutcomeConstants
{
public const string OnOutcomeInjectedEvent = "OnOutcomeInjected";
-
- public const string OnFaultInjectedEvent = "OnFaultInjectedEvent";
}
diff --git a/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.TResult.cs b/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.TResult.cs
deleted file mode 100644
index e68873980b..0000000000
--- a/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.TResult.cs
+++ /dev/null
@@ -1,158 +0,0 @@
-using System.Diagnostics.CodeAnalysis;
-using Polly.Simmy.Outcomes;
-
-namespace Polly.Simmy;
-
-///
-/// Extension methods for adding outcome to a .
-///
-internal static partial class OutcomePipelineBuilderExtensions
-{
- ///
- /// Adds a fault chaos strategy to the builder.
- ///
- /// The type of result the retry strategy handles.
- /// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
- /// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
- /// The exception to inject.
- /// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Exception fault)
- {
- Guard.NotNull(builder);
-
- builder.AddFaultCore(new FaultStrategyOptions
- {
- Enabled = enabled,
- InjectionRate = injectionRate,
- Fault = fault
- });
- return builder;
- }
-
- ///
- /// Adds a fault chaos strategy to the builder.
- ///
- /// The type of result the retry strategy handles.
- /// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
- /// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
- /// The exception generator delegate.
- /// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosFault(
- this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Func faultGenerator)
- {
- Guard.NotNull(builder);
-
- builder.AddFaultCore(new FaultStrategyOptions
- {
- Enabled = enabled,
- InjectionRate = injectionRate,
- FaultGenerator = (_) => new ValueTask(Task.FromResult(faultGenerator()))
- });
- return builder;
- }
-
- ///
- /// Adds a fault chaos strategy to the builder.
- ///
- /// The type of result the retry strategy handles.
- /// The builder instance.
- /// The fault strategy options.
- /// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, FaultStrategyOptions options)
- {
- Guard.NotNull(builder);
- Guard.NotNull(options);
-
- builder.AddFaultCore(options);
- return builder;
- }
-
- ///
- /// Adds an outcome chaos strategy to the builder.
- ///
- /// The type of result the retry strategy handles.
- /// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
- /// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
- /// The outcome to inject.
- /// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosResult(this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, TResult result)
- {
- Guard.NotNull(builder);
-
- builder.AddOutcomeCore>(new OutcomeStrategyOptions
- {
- Enabled = enabled,
- InjectionRate = injectionRate,
- Outcome = new Outcome(result)
- });
- return builder;
- }
-
- ///
- /// Adds an outcome chaos strategy to the builder.
- ///
- /// The type of result the retry strategy handles.
- /// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
- /// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
- /// The outcome generator delegate.
- /// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosResult(
- this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Func outcomeGenerator)
- {
- Guard.NotNull(builder);
-
- builder.AddOutcomeCore>(new OutcomeStrategyOptions
- {
- Enabled = enabled,
- InjectionRate = injectionRate,
- OutcomeGenerator = (_) => new ValueTask?>(Task.FromResult?>(Outcome.FromResult(outcomeGenerator())))
- });
- return builder;
- }
-
- ///
- /// Adds an outcome chaos strategy to the builder.
- ///
- /// The type of result the retry strategy handles.
- /// The builder instance.
- /// The outcome strategy options.
- /// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosResult(this ResiliencePipelineBuilder builder, OutcomeStrategyOptions options)
- {
- Guard.NotNull(builder);
- Guard.NotNull(options);
-
- builder.AddOutcomeCore>(options);
- return builder;
- }
-
- [UnconditionalSuppressMessage(
- "Trimming",
- "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
- Justification = "All options members preserved.")]
- private static void AddOutcomeCore(
- this ResiliencePipelineBuilder builder,
- OutcomeStrategyOptions options)
- {
- builder.AddStrategy(
- context => new OutcomeChaosStrategy(options, context.Telemetry),
- options);
- }
-
- [UnconditionalSuppressMessage(
- "Trimming",
- "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
- Justification = "All options members preserved.")]
- private static void AddFaultCore(
- this ResiliencePipelineBuilder builder,
- FaultStrategyOptions options)
- {
- builder.AddStrategy(
- context => new OutcomeChaosStrategy(options, context.Telemetry),
- options);
- }
-}
diff --git a/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.cs b/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.cs
index f0f397c21e..433ffb8148 100644
--- a/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.cs
+++ b/src/Polly.Core/Simmy/Outcomes/OutcomePipelineBuilderExtensions.cs
@@ -6,76 +6,73 @@ namespace Polly.Simmy;
///
/// Extension methods for adding outcome to a .
///
-internal static partial class OutcomePipelineBuilderExtensions
+internal static class OutcomePipelineBuilderExtensions
{
///
- /// Adds a fault chaos strategy to the builder.
+ /// Adds an outcome chaos strategy to the builder.
///
+ /// The type of result the retry strategy handles.
/// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
/// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
- /// The exception to inject.
+ /// The outcome to inject. For disposable outcomes use either the generator or the options overload.
/// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Exception fault)
+ public static ResiliencePipelineBuilder AddChaosResult(this ResiliencePipelineBuilder builder, double injectionRate, TResult result)
{
Guard.NotNull(builder);
- builder.AddFaultCore(new FaultStrategyOptions
+ builder.AddChaosResult(new OutcomeStrategyOptions
{
- Enabled = enabled,
+ Enabled = true,
InjectionRate = injectionRate,
- Fault = fault
+ OutcomeGenerator = (_) => new ValueTask?>(Task.FromResult?>(Outcome.FromResult(result)))
});
return builder;
}
///
- /// Adds a fault chaos strategy to the builder.
+ /// Adds an outcome chaos strategy to the builder.
///
+ /// The type of result the retry strategy handles.
/// The builder instance.
- /// A value that indicates whether or not the chaos strategy is enabled for a given execution.
/// The injection rate for a given execution, which the value should be between [0, 1] (inclusive).
- /// The exception generator delegate.
+ /// The outcome generator delegate.
/// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosFault(
- this ResiliencePipelineBuilder builder, bool enabled, double injectionRate, Func faultGenerator)
+ public static ResiliencePipelineBuilder AddChaosResult(
+ this ResiliencePipelineBuilder builder, double injectionRate, Func resultGenerator)
{
Guard.NotNull(builder);
- builder.AddFaultCore(new FaultStrategyOptions
+ builder.AddChaosResult(new OutcomeStrategyOptions
{
- Enabled = enabled,
+ Enabled = true,
InjectionRate = injectionRate,
- FaultGenerator = (_) => new ValueTask(Task.FromResult(faultGenerator()))
+ OutcomeGenerator = (_) => new ValueTask?>(Task.FromResult?>(Outcome.FromResult(resultGenerator())))
});
return builder;
}
///
- /// Adds a fault chaos strategy to the builder.
+ /// Adds an outcome chaos strategy to the builder.
///
+ /// The type of result the retry strategy handles.
/// The builder instance.
- /// The fault strategy options.
+ /// The outcome strategy options.
/// The builder instance with the retry strategy added.
- public static ResiliencePipelineBuilder AddChaosFault(this ResiliencePipelineBuilder builder, FaultStrategyOptions options)
- {
- Guard.NotNull(builder);
- Guard.NotNull(options);
-
- builder.AddFaultCore(options);
- return builder;
- }
-
[UnconditionalSuppressMessage(
"Trimming",
"IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code",
Justification = "All options members preserved.")]
- private static void AddFaultCore(this ResiliencePipelineBuilder builder, FaultStrategyOptions options)
+ public static ResiliencePipelineBuilder AddChaosResult<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TResult>(
+ this ResiliencePipelineBuilder builder,
+ OutcomeStrategyOptions options)
{
- builder.AddStrategy(context =>
- new OutcomeChaosStrategy