Skip to main content
Table of Contents

Class SagaProcess<TState>

Namespace
Stratara.Sagas.Abstractions
Assembly
Stratara.Sagas.dll

A saga with state, correlation and timeouts — the additional interface the stateless ISaga contract is left untouched for. The state is an aggregate of the process's own: it lives in an event stream keyed by the process and its correlation, is rebuilt by folding that stream, and changes only through the events the process emits. A timeout is a durable, owner-checked timer whose owner is the process; when the process completes, its timers go with it.

public abstract class SagaProcess<TState> : ISagaProcess, ISaga where TState : class, ISagaProcessState, new()

Type Parameters

TState

The process state: an aggregate with Apply methods for the events the process emits.

Inheritance
SagaProcess<TState>
Implements
Inherited Members
Extension Methods

Remarks

A fact may reach a process more than once — a host that dies after handling a fact and before recording that it read it hands the fact over again. Every delivery receives the state as recorded, which already reflects the first handling if that handling's events were recorded, so a process decides from its state and not from having seen the fact.

A step that schedules or cancels a timeout also emits the event that records why. A step's timer changes are applied before its events are recorded, so a timeout may reach OnTimeoutAsync(TState, string, ISagaProcessContext, CancellationToken) for a step whose events never were; the timeout receives the state as recorded, and a timeout that state does not expect does nothing.

Properties

StateType

The state type, an aggregate of the process's own.

public Type StateType { get; }

Property Value

Type

Methods

CorrelationOf(IEvent)

The correlation the fact belongs to; one process instance per correlation.

public abstract Guid CorrelationOf(IEvent @event)

Parameters

event IEvent

A fact the process handles.

Returns

Guid

The correlation id of the process instance the fact advances.

HandleAsync(TState, IEvent, ISagaProcessContext, CancellationToken)

Advances the process with a fact. Emit state events and schedule or cancel timeouts through the context.

public abstract Task HandleAsync(TState state, IEvent @event, ISagaProcessContext context, CancellationToken cancellationToken)

Parameters

state TState

The process state, folded from its stream; fresh for a process that has not started.

event IEvent

The fact, in commit order; possibly delivered before.

context ISagaProcessContext

Where emitted events and timeouts go.

cancellationToken CancellationToken

Propagated to the handling.

Returns

Task

A task that completes when the step has been decided.

Handles(IEvent)

Whether the process starts or advances on this fact.

public abstract bool Handles(IEvent @event)

Parameters

event IEvent

A fact from the store.

Returns

bool

true when the process handles the fact.

OnTimeoutAsync(TState, string, ISagaProcessContext, CancellationToken)

A timeout the process scheduled is due and the process has not completed.

public abstract Task OnTimeoutAsync(TState state, string purpose, ISagaProcessContext context, CancellationToken cancellationToken)

Parameters

state TState

The process state, folded from its stream; decide from it whether the timeout is still expected.

purpose string

The purpose the timeout was scheduled with.

context ISagaProcessContext

Where emitted events and timeouts go.

cancellationToken CancellationToken

Propagated to the handling.

Returns

Task

A task that completes when the step has been decided.