Skip to content

Class SagaExecutionStrategy

Namespace: Cephalon.Behaviors.Patterns.Strategies
Assembly: Cephalon.Behaviors.Patterns.dll

Executes behaviors that follow the saga-step pattern. Loads saga state before invocation and persists it after a successful execution. On exception, state is NOT saved so that explicit compensation logic can be applied.

public sealed class SagaExecutionStrategy : IBehaviorExecutionStrategy

objectSagaExecutionStrategy

IBehaviorExecutionStrategy

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

SagaExecutionStrategy(ISagaStateStore, ILogger<SagaExecutionStrategy>)

Section titled “ SagaExecutionStrategy(ISagaStateStore, ILogger<SagaExecutionStrategy>)”

Initializes a new instance of .

public SagaExecutionStrategy(ISagaStateStore store, ILogger<SagaExecutionStrategy> logger)

store ISagaStateStore

The saga state store used to load and persist saga state.

logger ILogger<SagaExecutionStrategy>

The logger used to report warnings and errors.

Gets the pattern identifier handled by this strategy.

public string Pattern { get; }

string

ExecuteAsync(BehaviorExecutionContext, CancellationToken)

Section titled “ ExecuteAsync(BehaviorExecutionContext, CancellationToken)”

Loads saga state, invokes the behavior slot, and saves the updated state on success. If the behavior throws, state is not persisted so compensation can be applied externally. The saga identifier is read from ; if not set, a new is generated and a warning is logged.

public Task<BehaviorExecutionResult> ExecuteAsync(BehaviorExecutionContext context, CancellationToken ct = default)

context BehaviorExecutionContext

The execution context for this invocation.

ct CancellationToken

A token that cancels the execution.

Task<BehaviorExecutionResult>

A result with HTTP 200 and the behavior output.