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.
| Member | Type | Purpose |
|---|---|---|
SagaId | Guid | Unique saga identifier |
Phase | SagaPhase | Current lifecycle phase |
LastCompletedStepIndex | int | Index of last completed step |
CorrelationId | string? | Optional correlation identifier |
StartedAt | DateTimeOffset? | Timestamp when the saga started |
StepHash | string? | 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.
| Property | Type | Purpose |
|---|---|---|
SagaId | Guid | Unique saga identifier |
Input | TInput | Saga input payload |
CorrelationId | string? | Optional correlation identifier |
Lifecycle Events
These events represent saga lifecycle transitions and step outcomes. See the Sagas Abstractions folder.
| Event | Purpose |
|---|---|
SagaStartedEvent | Saga start event with SagaId, StepHash, StartedAt, and CorrelationId |
SagaInputProvided<TInput> | Captures the saga input payload |
SagaStepCompleted | Records a successful step completion |
SagaStepFailed | Records a failed step with error details |
SagaCompensating | Indicates compensation begins from a step index |
SagaStepCompensated | Records a compensated step |
SagaCompleted | Saga completed successfully |
SagaCompensated | Compensation completed |
SagaFailed | Saga 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.
| Member | Purpose |
|---|---|
Success | Indicates step success |
ErrorCode | Error code on failure |
ErrorMessage | Error message on failure |
Events | Emitted events on success |
CompensationResult
CompensationResult communicates success/failure/skip for compensation.
| Member | Purpose |
|---|---|
Success | Compensation succeeded |
Skipped | Compensation skipped |
ErrorCode | Error code on failure |
ErrorMessage | Error 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
ISagaStateandSagaPhasedefine saga state shape and lifecycle phases.- Steps implement
ISagaStep<TSaga>and optionallyICompensatable<TSaga>, usingStepResultandCompensationResultfor outcomes. AddSagaOrchestrationandAddSagaStepInfoare the core registration helpers.