Overview
Reactive strategies handle specific exceptions thrown or results returned by callbacks. This guide demonstrates how to create a Result Reporting Strategy that listens for specific results and reports them to other components.Reactive strategies inherit from
ResilienceStrategy<T> and use predicates to determine whether to handle an outcome.Implementation
Strategy Class
Reactive strategies should be internal and not exposed in the public API. Configure them through extension methods and options.Reactive strategies use the
ShouldHandle predicate to decide whether to handle the outcome of a user callback.Predicate Arguments
The predicate arguments follow the{StrategyName}PredicateArguments naming pattern:
Event Arguments
For reporting outcomes, define event-specific arguments:Options
1
Define Generic Options
Create a public options class that inherits from
ResilienceStrategyOptions:2
Add Non-Generic Support (Optional)
For non-generic pipelines, derive from the generic options:
Extension Methods
Create extension methods to register the strategy with the pipeline builder:Usage Examples
Key Takeaways
Strategy Implementation
Strategy Implementation
- Inherit from
ResilienceStrategy<T> - Keep the strategy class internal
- Use
ShouldHandlepredicate to determine if an outcome should be handled - Report events using
ResilienceStrategyTelemetry
Arguments
Arguments
- Always include
ContextandOutcomeproperties - Use readonly structs for arguments
- Follow naming convention:
{DelegateName}Arguments
Options
Options
- Inherit from
ResilienceStrategyOptions - Provide sensible defaults where possible
- Use validation attributes (e.g.,
[Required]) - Support both generic and non-generic variants
Extension Methods
Extension Methods
- Return the builder to support fluent API
- Use
AddStrategymethod for registration - Automatic validation of options
Resources
Result Reporting Sample
Complete working example from this guide
Retry Strategy Source
Built-in retry strategy implementation
Fallback Strategy Source
Built-in fallback strategy implementation
Extensibility Overview
Learn about extensibility basics