TheDocumentation 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.
InjectBehaviour policy is Simmy’s most flexible chaos tool: it runs any arbitrary Action before the wrapped call executes. Where InjectException and InjectResult are constrained to fault types that Polly can model directly, InjectBehaviour gives you a free canvas — restart a virtual machine, poison a cache entry, toggle a feature flag, emit a monitoring alert, or trigger any other side effect your chaos scenario requires. The injected behaviour fires before the wrapped call, and provided no exception is thrown inside it, execution continues normally.
Factory method signatures
Behaviour delegate returns Task, allowing await inside the injected action.
Quick start
Define the behaviour to inject
Write the action you want Simmy to execute. This can be any side-effecting code — calling an infrastructure API, modifying shared state, or writing to a log.
Build the chaos policy
Configure the behaviour, injection rate, and an enabled predicate through the fluent builder.An injection rate of
0.01 means roughly 1% of calls trigger the behaviour. .EnabledWhen accepts a Func<Context, CancellationToken, bool> delegate, so you can read a feature flag or configuration value at call time to decide whether chaos is active.Fluent option methods
.Behaviour(action)
An
Action (or Action<Context, CancellationToken>) containing the side-effecting code to run before the wrapped call..InjectionRate(double)
A value between
0.0 and 1.0 controlling how often the behaviour fires..EnabledWhen(func)
A delegate that is evaluated at execution time to determine whether the monkey policy should be active.
Context-aware behaviour delegate
PassAction<Context, CancellationToken> to receive the Polly Context and the execution’s CancellationToken inside the injected behaviour. This lets you target specific operations by OperationKey, read context data, or respect cooperative cancellation.
Async variant
For async code paths, useMonkeyPolicy.InjectBehaviourAsync. The behaviour delegate is Func<Task> or Func<Context, CancellationToken, Task>, which means your injected action can await infrastructure calls.
Use cases
Infrastructure simulation
Restart services, clear caches, or modify configuration stores to simulate node failures and infrastructure events without touching real infrastructure.
Shared state mutation
Corrupt or clear shared state (queues, caches, counters) to verify that dependent services degrade gracefully rather than producing incorrect results.
Monitoring and alerting
Emit synthetic events to your monitoring system to test that alerts fire correctly and that on-call runbooks are accurate.
Feature flag toggling
Flip feature flags mid-execution to test how application code behaves when a feature is enabled or disabled during an in-flight request.
Execution order
The injected behaviour always runs before the wrapped call. If the behaviour throws an exception, the wrapped call is skipped and the exception propagates. If the behaviour completes without error, execution continues normally and the wrapped call runs regardless of what the behaviour did.Using inside a PolicyWrap
Place theInjectBehaviour policy innermost in a PolicyWrap so that outer resilience policies handle any knock-on effects of the injected behaviour — for example, if the behaviour clears a cache and the subsequent call to refill it fails.
Dynamic injection rate and enabled flag
BothInjectionRate and EnabledWhen support delegate forms, so chaos settings can be read from an external configuration service at call time without restarting the application.
Reference
See Policy Options for the full reference on shared fluent options, including all delegate overloads forInjectionRate, Enabled, and EnabledWhen.