Skip to main content

Saga Public APIs

Overview

This page lists the public saga contracts and registration helpers used by Mississippi saga orchestration.

Saga State Contract

ISagaState defines the required saga state properties.

MemberTypePurpose
SagaIdGuidUnique saga identifier
PhaseSagaPhaseCurrent lifecycle phase
LastCompletedStepIndexintIndex of last completed step
CorrelationIdstring?Optional correlation identifier
StartedAtDateTimeOffset?Timestamp when the saga started
StepHashstring?Hash of ordered steps

SagaPhase describes lifecycle phases: NotStarted, Running, Compensating, Completed, Compensated, and Failed. See ISagaState.cs.

Start Command and Lifecycle Events

Start Command

StartSagaCommand<TInput> starts a saga instance with an input payload.

PropertyTypePurpose
SagaIdGuidUnique saga identifier
InputTInputSaga input payload
CorrelationIdstring?Optional correlation identifier

Lifecycle Events

These events represent saga lifecycle transitions and step outcomes. See the Sagas Abstractions folder.

EventPurpose
SagaStartedEventSaga start event with SagaId, StepHash, StartedAt, and CorrelationId
SagaInputProvided<TInput>Captures the saga input payload
SagaStepCompletedRecords a successful step completion
SagaStepFailedRecords a failed step with error details
SagaCompensatingIndicates compensation begins from a step index
SagaStepCompensatedRecords a compensated step
SagaCompletedSaga completed successfully
SagaCompensatedCompensation completed
SagaFailedSaga failed without compensation or after compensation failure

Steps and Results

ISagaStep and ICompensatable

ISagaStep<TSaga> executes a step and returns StepResult.

ICompensatable<TSaga> provides optional compensation and returns CompensationResult.

StepResult

StepResult communicates success/failure and optional emitted events.

MemberPurpose
SuccessIndicates step success
ErrorCodeError code on failure
ErrorMessageError message on failure
EventsEmitted events on success

CompensationResult

CompensationResult communicates success/failure/skip for compensation.

MemberPurpose
SuccessCompensation succeeded
SkippedCompensation skipped
ErrorCodeError code on failure
ErrorMessageError message on failure or skip

Step Metadata

SagaStepAttribute

SagaStepAttribute<TSaga> marks a class as a saga step, defines a zero-based order, and binds the step to a saga state type via the type parameter.

SagaStepInfo and Providers

SagaStepInfo describes a step with index, name, type, and compensation capability.

ISagaStepInfoProvider<TSaga> exposes ordered SagaStepInfo entries for orchestration.

AddSagaStepInfo<TSaga> registers a default provider for a saga state.

Registrations

AddSagaOrchestration<TSaga, TInput> wires saga infrastructure into DI.

It registers:

  • Event types for saga lifecycle and step events.
  • The StartSagaCommand<TInput> handler.
  • Reducers for saga lifecycle events.
  • The saga orchestration effect as an event effect.

Generator Attributes

GenerateSagaEndpointsAttribute

[GenerateSagaEndpoints] marks a saga state for infrastructure code generation. It includes optional FeatureKey, InputType, and RoutePrefix settings, with documented defaults and a route pattern of api/sagas/{RoutePrefix}/{sagaId}.

GenerateSagaEndpointsAttribute (generic)

[GenerateSagaEndpoints<TInput>] provides the same behavior with a strongly typed input payload.

GenerateSagaStatusReducersAttribute

[GenerateSagaStatusReducers] marks a projection for saga status reducer generation.

Summary

Next Steps