Class SaveSagaRequest<TSagaState>
Represents a data request to save a saga state to the Postgres saga store.
public sealed class SaveSagaRequest<TSagaState> : DataRequestBase<IDbConnection, int>, IDataRequest<IDbConnection, int>, IDataRequest where TSagaState : SagaState
Type Parameters
TSagaStateThe type of the saga state.
- Inheritance
-
SaveSagaRequest<TSagaState>
- Implements
- Inherited Members
Remarks
This request uses Postgres's INSERT ON CONFLICT (upsert) pattern for an atomic,
single-round-trip, version-gated save. It is the optimistic-concurrency analogue of
SqlServerSagaStore's version-gated MERGE (store-owns-increment).
The saga state is serialized to JSONB for efficient storage and querying capabilities.
Constructors
SaveSagaRequest(TSagaState, PostgresSagaOptions, DispatchJsonSerializer, TenantScope, CancellationToken)
Initializes a new instance of the SaveSagaRequest<TSagaState> class.
[RequiresUnreferencedCode("JSON serialization and deserialization might require types that cannot be statically analyzed.")]
[RequiresDynamicCode("JSON serialization and deserialization might require runtime code generation.")]
public SaveSagaRequest(TSagaState sagaState, PostgresSagaOptions options, DispatchJsonSerializer serializer, TenantScope scope, CancellationToken cancellationToken)
Parameters
sagaStateTSagaStateThe saga state to save.
optionsPostgresSagaOptionsThe Postgres saga store options.
serializerDispatchJsonSerializerThe JSON serializer for serializing saga state.
scopeTenantScopeThe tenant scope, and the sole authority for the row's tenant. The saga row is stamped from this scope and the version-gated UPDATE additionally requires the persisted tenant to equal it, so a save under one tenant can never overwrite another tenant's saga. Untenanted stamps the reserved untenanted partition, not an absent tenant, so the term is present either way and the match predicate is unconditional. A tenant-scoped scope cannot be constructed without a tenant, so a predicate-less save while tenancy is active is unrepresentable.
sagaState.TenantIddoes NOT influence where the row is stored, under any scope. It travels in the serialized payload only. The read side is given a saga id and a scope — never a state — so deriving the discriminator from the saga's own tenant would let the two sides resolve different terms for the same saga and write it where no read looks.cancellationTokenCancellationTokenThe cancellation token.