Documentation 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.
InjectBehaviourOptions and InjectBehaviourAsyncOptions are the configuration objects you pass to MonkeyPolicy.InjectBehaviour and MonkeyPolicy.InjectBehaviourAsync. Unlike the outcome and latency policies, behaviour injection lets you run any arbitrary Action — or async Func<Task> — before the wrapped delegate executes. This is useful for chaos scenarios that don’t fit neatly into “throw an exception” or “add a delay”: for example, writing to a corrupted cache, publishing a spurious event, exhausting a connection pool, or logging diagnostic information during a chaos run. The behaviour is always injected before the wrapped delegate executes, and the wrapped call proceeds normally afterwards.
Namespaces
InjectBehaviourOptions (sync)
InjectionRate and Enabled delegates from InjectOptionsBase. The internal BehaviourInternal property holds the Action<Context, CancellationToken> delegate and is populated by the .Behaviour(...) extension methods below.
InjectBehaviourAsyncOptions (async)
InjectionRate and Enabled delegates (Task<double> / Task<bool>) from InjectOptionsAsyncBase. The internal BehaviourInternal property is Func<Context, CancellationToken, Task>.
Behaviour extension methods
.Behaviour(Action) — sync, no context
Configures a simple parameterless action to execute before the wrapped delegate.
The sync options object being configured (supplied automatically by the fluent chain).
A parameterless action invoked at injection-time, before the wrapped call. The Polly context and cancellation token are not exposed; use the context-aware overload if you need them.
.Behaviour(Action<Context, CancellationToken>) — sync with context
Configures an action that receives the current Polly Context and CancellationToken at injection-time.
The sync options object being configured.
A synchronous action invoked with the current
Context and CancellationToken. Use ctx.OperationKey or custom context data to tailor the behaviour per execution, and honour the cancellation token if the action performs any blocking work..Behaviour(Func<Task>) — async, no context
Configures an async action with no context access. Internally promoted to Func<Context, CancellationToken, Task>.
The async options object being configured.
A parameterless async function returning
Task. Use this for straightforward async side-effects that do not need access to the Polly context or cancellation token..Behaviour(Func<Context, CancellationToken, Task>) — async with context
Configures an async action that receives the Polly Context and CancellationToken.
The async options object being configured.
An async delegate returning
Task. Receives the current Polly Context and CancellationToken, making it the most flexible overload. Suitable for async chaos actions that depend on execution context or need to respect cancellation, such as writing to a test database or calling an external chaos-coordination API.Inherited base options
InjectBehaviourOptions inherits from InjectOptionsBase and InjectBehaviourAsyncOptions from InjectOptionsAsyncBase. The following methods control when and how often the behaviour is triggered. InjectionRate and Enabled are both required — the factory throws ArgumentNullException if either is missing.
Sync base (InjectOptionsBaseExtensions)
.Enabled() — always on
.Enabled(true).
.Enabled(bool)
true to activate behaviour injection; false to deactivate it for all calls regardless of injection rate. Useful for toggling chaos off at startup when reading configuration..EnabledWhen(Func<Context, CancellationToken, bool>)
A synchronous delegate evaluated on every execution. Return
true to allow chaos injection for that call; false to skip it. Common patterns include checking an environment variable, reading an in-memory feature flag, or inspecting ctx.OperationKey..InjectionRate(double)
A constant rate in
[0, 1]. 0.0 means the behaviour is never injected; 1.0 means it runs before every call. Values outside this range throw ArgumentOutOfRangeException..InjectionRate(Func<Context, CancellationToken, double>)
A delegate evaluated on each execution to supply a dynamic injection rate. Enables graduated chaos rollouts — for example, increasing the rate from 1% to 10% over time without redeploying.
Async base (InjectOptionsAsyncBaseExtensions)
The async base provides the same .Enabled(), .Enabled(bool), and .InjectionRate(double) overloads as the sync base, plus async-delegate variants:
.EnabledWhen(Func<Context, CancellationToken, Task<bool>>)
An async delegate returning
Task<bool>. Use this when the enabled check must call an async service such as a remote feature-flag or chaos-orchestration API..InjectionRate(Func<Context, CancellationToken, Task<double>>)
An async delegate returning
Task<double> in [0, 1]. Allows the injection rate to be sourced from a live configuration service on every execution.