Skip to main content

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:
Reactive arguments must always contain both Context and Outcome properties.

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:
Using options as a public contract ensures flexibility and allows you to add new members without breaking changes.

Extension Methods

Create extension methods to register the strategy with the pipeline builder:

Usage Examples

Key Takeaways

  • Inherit from ResilienceStrategy<T>
  • Keep the strategy class internal
  • Use ShouldHandle predicate to determine if an outcome should be handled
  • Report events using ResilienceStrategyTelemetry
  • Always include Context and Outcome properties
  • Use readonly structs for arguments
  • Follow naming convention: {DelegateName}Arguments
  • Inherit from ResilienceStrategyOptions
  • Provide sensible defaults where possible
  • Use validation attributes (e.g., [Required])
  • Support both generic and non-generic variants
  • Return the builder to support fluent API
  • Use AddStrategy method 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