Every Simmy monkey policy is configured through a fluent builder that is passed as a callback to the relevantDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/Polly-Contrib/Simmy/llms.txt
Use this file to discover all available pages before exploring further.
MonkeyPolicy factory method. The callback receives a typed options object — for example InjectOutcomeOptions<Exception> or InjectLatencyOptions — and you chain extension methods on it to define what chaos to inject, how often, and when. All options that accept a delegate receive both a Polly Context and a CancellationToken, letting you vary behaviour dynamically at call time.
Every policy must have
Enabled (or EnabledWhen), InjectionRate, and the chaos payload (e.g. Fault, Result, Latency, or Behaviour) configured before it is built. Missing any of these three parts will cause an ArgumentNullException to be thrown from the factory method.Enabled / EnabledWhen
These options live onInjectOptionsBase (sync) and InjectOptionsAsyncBase (async) and are available on every Simmy policy.
Marks the policy as unconditionally enabled. Equivalent to calling
Enabled(true).Enables or disables the policy based on a boolean value known at configuration time. Useful when the flag is read from app config at startup.
Accepts a delegate that is evaluated on every policy execution. Returning
true means the policy is active for that call; returning false means the call passes through untouched.InjectionRate
Controls how often the chaos is triggered. A value of0.05 means chaos is injected in approximately 5 % of executions; 1.0 means every execution is affected.
Sets a constant injection rate from a
double in the range [0, 1]. The value is validated at configuration time (since v0.3.0); an out-of-range value throws immediately rather than waiting until the first execution.Evaluates the delegate on every execution to obtain the current injection rate. This allows rates to be driven from external configuration without redeploying the app.
Fault
Applies toInjectOutcomeOptions<Exception> (sync) and InjectOutcomeAsyncOptions<Exception> (async). Used when building a policy with MonkeyPolicy.InjectException or MonkeyPolicy.InjectExceptionAsync.
Configures a specific exception instance to throw. The same instance is re-thrown on every affected execution.
Delegates exception creation to a factory function so you can vary the exception type or message per call.
- Sync (concrete exception)
- Async (concrete exception)
- Async (delegate — Task<Exception>)
Result
Applies toInjectOutcomeOptions<TResult> (sync) and InjectOutcomeAsyncOptions<TResult> (async). Used when building a policy with MonkeyPolicy.InjectResult<TResult> or MonkeyPolicy.InjectResultAsync<TResult>.
Returns a constant substitute result value instead of executing the wrapped call.
Computes the substitute result through a delegate, allowing you to vary the injected value per execution.
Latency
Applies toInjectLatencyOptions (sync) and InjectLatencyAsyncOptions (async). Used when building a policy with MonkeyPolicy.InjectLatency or MonkeyPolicy.InjectLatencyAsync.
Injects a fixed delay before the wrapped call executes.
Computes the delay from a delegate. This lets you serve latency values from external configuration and adjust them without redeploying.
Async latency policies introduced in v0.2.0 are fully cancellable: if the
CancellationToken is triggered during the injected delay, the delay is cancelled and the token’s cancellation propagates normally.Behaviour
Applies toInjectBehaviourOptions (sync) and InjectBehaviourAsyncOptions (async). Used when building a policy with MonkeyPolicy.InjectBehaviour or MonkeyPolicy.InjectBehaviourAsync.
Runs a simple, parameterless action before the wrapped call. Handy for side effects such as clearing a cache or writing a log entry.
Runs an action that receives the current Polly
Context and CancellationToken. Use this when the behaviour needs to vary based on the calling context or must respect cancellation.- Sync (Action)
- Async (Func<Task>)
- Async (Func<Context, CancellationToken, Task>)
Quick Reference
| Option | Sync overloads | Async overloads | Applies to |
|---|---|---|---|
Enabled() | ✓ | ✓ | All policies |
Enabled(bool) | ✓ | ✓ | All policies |
EnabledWhen(Func<Context, CancellationToken, bool>) | ✓ | — | All policies (sync) |
EnabledWhen(Func<Context, CancellationToken, Task<bool>>) | — | ✓ | All policies (async) |
InjectionRate(double) | ✓ | ✓ | All policies |
InjectionRate(Func<…, double>) | ✓ | — | All policies (sync) |
InjectionRate(Func<…, Task<double>>) | — | ✓ | All policies (async) |
Fault(Exception) | ✓ | ✓ | InjectException |
Fault(Func<…, Exception>) | ✓ | — | InjectException (sync) |
Fault(Func<…, Task<Exception>>) | — | ✓ | InjectException (async) |
Result<TResult>(TResult) | ✓ | ✓ | InjectResult |
Result<TResult>(Func<…, TResult>) | ✓ | — | InjectResult (sync) |
Result<TResult>(Func<…, Task<TResult>>) | — | ✓ | InjectResult (async) |
Latency(TimeSpan) | ✓ | ✓ | InjectLatency |
Latency(Func<…, TimeSpan>) | ✓ | — | InjectLatency (sync) |
Latency(Func<…, Task<TimeSpan>>) | — | ✓ | InjectLatency (async) |
Behaviour(Action) | ✓ | — | InjectBehaviour (sync) |
Behaviour(Action<Context, CancellationToken>) | ✓ | — | InjectBehaviour (sync) |
Behaviour(Func<Task>) | — | ✓ | InjectBehaviour (async) |
Behaviour(Func<Context, CancellationToken, Task>) | — | ✓ | InjectBehaviour (async) |