Simmy integrates naturally with the .NET dependency injection model. Because chaos policies are justDocumentation 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.
IAsyncPolicy or IPolicy instances, you can register them through IServiceCollection the same way you register any other Polly policy — but with an important twist: you want chaos active only in specific environments, only for specific operations, and ideally without touching your existing resilience policy code at all. The three patterns below show exactly how to achieve that.
The Simmy sample app contains full working implementations of all three patterns demonstrated here. It is the canonical reference for production-style DI wiring.
Pattern 1: Environment-Gated Startup
The simplest way to keep chaos out of production is to register chaos policies only when the host environment is notProduction. Your normal Polly policies are registered unconditionally; the chaos layer is added only in Dev and Staging builds.
Register your baseline Polly policies
Add your retry, timeout, and circuit-breaker policies as you normally would. These registrations stay completely unchanged — Simmy adds its own layer on top.
Add the chaos layer for non-production environments
Wrap the same
HttpClient registration with a chaos policy only when the environment is not Production. The chaos policy is injected innermost — after the resilience policies — so the outer resilience policies react to anything Simmy injects.Pattern 2: Inserting Chaos Without Changing Existing Policy Code
One of Simmy’s main design goals is that you should be able to inject chaos into an existing app without modifying any existing Polly configuration code. You achieve this by wrapping whatever policies are already registered with a newMonkeyPolicy wrapper at registration time.
The trick is that PolicyWrap evaluates policies from outermost to innermost. By adding the chaos policy last in the AddPolicyHandler chain (i.e. innermost), the existing outer policies — retry, circuit breaker, fallback — handle whatever Simmy throws or returns.
HttpResponseMessage) instead of an exception, which lets you simulate bad HTTP responses — for example a 503 Service Unavailable — that your retry and fallback policies should handle:
Pattern 3: Driving Chaos from External Configuration
Hardcoding.Enabled() or .InjectionRate(0.05) is fine for local development, but for staging environments you want to be able to flip chaos on and off — and change injection rates — without redeploying. Simmy supports this through EnabledWhen and the delegate overload of InjectionRate, both of which receive the Polly Context and a CancellationToken.
The pattern is to inject a settings provider (e.g. via IOptions<ChaosSettings> or a custom IChaosSettingsProvider) and read the current settings on every execution. Because Polly’s Context.OperationKey identifies which operation is running, you can enable chaos selectively per-operation.
appsettings.Development.json section might look like this:
When using
EnabledWhen or the delegate overload of InjectionRate, always tag each Execute call with a Context carrying the appropriate OperationKey. Without it, ctx.OperationKey will be empty and your per-operation settings won’t resolve correctly.