API reference — Workflows

Nuvora.Nexus.Relay.Sagas

Sagas / process managers (state-stored, scheduler-backed timeouts) for Nuvora Nexus Relay

dotnet add package Nuvora.Nexus.Relay.Sagas

Nuvora.Nexus.Relay.Sagas

ISagaState

public interface ISagaState

Marker for a saga’s serialized state payload (stored as jsonb in relay_sagas).

Saga<TState>

public abstract class Saga<TState> where TState : class, ISagaState, new()

Base class for a state-stored saga / process manager. Derive, supply a TState, and wire reactions in Saga.Configure. Handler methods read/write Saga.State and request side effects (Saga.Publish, Saga.Send, Saga.RequestTimeout, Saga.CancelTimeouts, Saga.Complete) which the coordinator flushes atomically with the state save. Sagas coordinate via messages/timeouts; they do not mutate event-sourced aggregates directly (send a command instead).

Properties

TState State { get; internal set; }

The saga’s persisted state for the current transition.

string? CurrentState { get; }

The declarative current-state name (null for purely imperative sagas).

Methods

abstract void Configure(ISagaConfigurator<TState> configurator)

Wire up correlation and handlers.

void CancelTimeouts()

Cancel all pending timeouts for this saga.

void Compensate()

Roll the routing slip back: replay the recorded compensations in reverse order.

void Complete()

Mark the saga completed; later messages for this correlation are ignored.

void Publish(IIntegrationEvent integrationEvent)

Publish an integration event (staged on the outbox).

void RecordCompensation(ICommand compensation)

Record the compensating command for a forward leg just performed (Courier-style routing slip).

void RequestTimeout<TTimeout>(TimeSpan delay, TTimeout payload)

Request a timeout delivered back to the saga after delay.

void Send(ICommand command)

Send a command (scheduled for immediate, reliable delivery).

void TransitionTo(string state)

Set the declarative current-state name (used by the state-machine DSL).

SagaExecutionContext

public sealed class SagaExecutionContext

Buffers the side effects a saga requests during one transition — outgoing integration events, commands, timeout requests/cancellations, completion and state transitions. The coordinator flushes them onto the same transaction as the saga-state save, so a saga’s reaction is atomic.

Constructors

SagaExecutionContext(Guid sagaId, string correlationKey, Guid? tenantId, string? currentState)

Properties

Guid SagaId { get; }
Guid? TenantId { get; }
bool Completed { get; private set; }
string CorrelationKey { get; }
string? CurrentState { get; private set; }

Methods

void CancelTimeouts()

Cancel all pending timeouts for this saga.

void Compensate()

Roll the routing slip back: every compensation recorded for a completed forward leg (across this and prior transitions) is replayed in reverse order as a reliable command, exactly once even across redelivery.

void Complete()

Mark the saga completed (no further messages will be processed).

void Publish(IIntegrationEvent integrationEvent)

Publish an integration event (staged on the outbox, atomic with the state save).

void RecordCompensation(ICommand compensation)

Record the compensating command for a forward leg just performed (Courier-style routing slip). It is appended to the saga’s persisted itinerary; if the slip is later rolled back (SagaExecutionContext.Compensate) the recorded compensations are replayed in reverse order.

void RequestTimeout(Type timeoutType, object payload, TimeSpan delay)

Request a timeout: payload is delivered back to the saga after delay.

void Send(ICommand command)

Send a command (scheduled for immediate delivery via the scheduler, atomic + reliable).

void TransitionTo(string state)

Set the declarative current-state name.

SagaMissingPolicy

public enum SagaMissingPolicy

What to do when a non-start message correlates to no existing saga instance.

Values

  • Ignore — Drop the message (default): a late/duplicate event for a completed saga is normal.
  • Fault — Throw, so the message is redelivered/retried (use for “this saga must exist” invariants).

SagaOptions

public sealed class SagaOptions

Configuration for the saga engine.

Properties

SagaMissingPolicy MissingPolicy { get; set; }

Policy for a non-start message that matches no live saga. Default SagaMissingPolicy.Ignore.

SagaRecord

public class SagaRecord

Persisted saga instance (relay_sagas). State is stored as jsonb; SagaRecord.Version is an optimistic-concurrency token so two concurrent deliveries to the same saga cannot both commit — the loser is redelivered (inbox) or retried (scheduler). One live instance per (SagaType, CorrelationKey) (tenant-prefixed under multi-tenancy).

Properties

DateTimeOffset CreatedAt { get; set; }
DateTimeOffset UpdatedAt { get; set; }
Guid SagaId { get; set; }
Guid? TenantId { get; set; }

Owning tenant (null = global).

SagaStatus Status { get; set; }
int ItineraryPosition { get; set; }

Number of itinerary compensations already replayed, counted from the start: entries below this index are compensated, entries at or above it are not. Compensated legs always form a prefix (forward retries append at the end; a rollback compensates the whole remaining suffix), so a retried/redelivered rollback resumes from committed state instead of re-issuing compensations, and legs appended by a forward retry after a rollback are still compensated exactly once.

int Version { get; set; }

Optimistic-concurrency token.

string CorrelationKey { get; set; }

Canonical string form of the correlation value.

string SagaType { get; set; }

Stable saga type name (the invoker key).

string State { get; set; }

Serialized saga state (jsonb).

string? CurrentState { get; set; }

Declarative-DSL current-state name (null for imperative sagas).

string? Itinerary { get; set; }

Courier-style routing-slip log: a JSON array of the compensating commands recorded for completed forward legs (in forward order), or null when the saga uses no routing slip. On rollback they replay in reverse.

SagaStatus

public enum SagaStatus

Lifecycle status of a saga instance (numeric values are persisted — do not reorder).

Values

  • Active — Live: still reacting to messages and timeouts.
  • Completed — Finished normally; further messages for this correlation are ignored.
  • Faulted — Failed past its retry budget; left for operator inspection.

SagaTrigger<TSaga, TState, TEvent>

public abstract class SagaTrigger<TSaga, TState, TEvent> : IIntegrationEventHandler<TEvent> where TSaga : Saga<TState>, new() where TState : class, ISagaState, new() where TEvent : IIntegrationEvent

Base for an integration-event handler that routes an event into a saga. Derive a concrete trigger per start/continue event so the normal AddRelay handler scan discovers it and the inbox delivers to it inside its transaction:

public sealed class OrderPlacedTrigger(ISagaCoordinator c)
    : SagaTrigger<OrderSaga, OrderState, OrderPlaced>(c);

Constructors

SagaTrigger(ISagaCoordinator coordinator)

Methods

Task Handle(TEvent message, CancellationToken cancellationToken)

ServiceCollectionExtensions

public static class ServiceCollectionExtensions

Registration helpers for the saga engine.

Methods

static IServiceCollection AddRelaySaga<TSaga, TState>(this IServiceCollection services)

Registers a saga type with the engine.

static IServiceCollection AddRelaySagas(this IServiceCollection services, Action<SagaOptions>? configure = null)

Registers the saga engine (registry, coordinator, timeout dispatcher). Requires the scheduler (AddRelayScheduling + AddRelaySchedulerEfCore), the saga repository (AddRelaySagasEfCore) and core Relay (AddRelay). Register each saga with ServiceCollectionExtensions.AddRelaySaga and a SagaTrigger per start/continue event.

Nuvora.Nexus.Relay.Sagas.Configuration

ISagaConfigurator<TState>

public interface ISagaConfigurator<TState> where TState : class, ISagaState

Builds a saga’s behaviour: which integration events correlate to it (and which start a new instance), and the handler that runs for each event/timeout. Called from Saga.Configure. Handlers are ordinary instance methods, so they read/write State and call the protected side-effect helpers directly.

Methods

ISagaConfigurator<TState> Handle<TEvent>(Func<TEvent, object> correlate, Func<TEvent, CancellationToken, Task> handler)

A correlated event handled by an existing saga (ignored when none matches, by default).

ISagaConfigurator<TState> OnTimeout<TTimeout>(Func<TTimeout, CancellationToken, Task> handler)

A timeout payload type, delivered back to the saga (correlated by saga id, not a key).

ISagaConfigurator<TState> StartedBy<TEvent>(Func<TEvent, object> correlate, Func<TEvent, CancellationToken, Task> handler)

A correlated event that, when no instance exists, starts a new saga.

SagaConfigurator<TState>

public sealed class SagaConfigurator<TState> : ISagaConfigurator<TState> where TState : class, ISagaState

Collects a saga’s correlation expressions, start triggers and (instance-bound) handlers. Built once per delivery on the fresh saga instance, so the captured handler delegates operate on that instance’s State/Context; the correlation/start-trigger metadata it records is instance-independent and is also read once at registration for routing.

Properties

Dictionary<Type, Func<object, CancellationToken, Task>> Handlers { get; }
Dictionary<Type, Func<object, string>> Correlations { get; }
HashSet<Type> StartTriggers { get; }
IEnumerable<Type> IntegrationEventTypes { get; }

Correlated event types that arrive over the broker/inbox (i.e. integration events).

Methods

Func<object, CancellationToken, Task>? GetHandler(Type messageType)
ISagaConfigurator<TState> Handle<TEvent>(Func<TEvent, object> correlate, Func<TEvent, CancellationToken, Task> handler)

A correlated event handled by an existing saga (ignored when none matches, by default).

ISagaConfigurator<TState> OnTimeout<TTimeout>(Func<TTimeout, CancellationToken, Task> handler)

A timeout payload type, delivered back to the saga (correlated by saga id, not a key).

ISagaConfigurator<TState> StartedBy<TEvent>(Func<TEvent, object> correlate, Func<TEvent, CancellationToken, Task> handler)

A correlated event that, when no instance exists, starts a new saga.

Nuvora.Nexus.Relay.Sagas.Courier

CourierExecutor

public sealed class CourierExecutor

Runs an itinerary of ICourierActivity in order. If an activity throws, the activities that already completed are compensated in reverse order (LIFO); compensation is best-effort and always runs every completed step even if some compensations themselves throw (those are collected on the result). A standalone alternative to the in-saga compensation log, for distributed transactions without two-phase commit.

Methods

Task<CourierResult> ExecuteAsync(IReadOnlyList<ICourierActivity> itinerary, CancellationToken cancellationToken = default(CancellationToken))

CourierResult

public sealed class CourierResult

The outcome of running a Courier itinerary.

Properties

Exception? Failure { get; }

The activity failure that triggered compensation (null when CourierResult.Succeeded).

IReadOnlyList<Exception> CompensationErrors { get; }

Any exceptions thrown by compensating actions (best-effort; compensation always continues).

bool Succeeded { get; }

True if every activity executed; false if a failure triggered compensation.

Methods

static CourierResult Compensated(Exception failure, IReadOnlyList<Exception> compensationErrors)
static CourierResult Completed()

ICourierActivity

public interface ICourierActivity

A Courier activity: one forward step of a distributed transaction together with its compensating action. An itinerary of activities is executed in order; if any step fails, the already-completed activities are compensated in reverse (LIFO) — a saga/routing-slip without 2PC.

Methods

Task CompensateAsync(CancellationToken cancellationToken = default(CancellationToken))

Undoes the forward action (only called for activities that completed ICourierActivity.ExecuteAsync).

Task ExecuteAsync(CancellationToken cancellationToken = default(CancellationToken))

Performs the forward action.

Nuvora.Nexus.Relay.Sagas.Infrastructure

ISagaReadStore

public interface ISagaReadStore

Background-safe, read-only query surface over persisted sagas. Unlike ISagaRepository (which is bound to the command’s ambient DbContext and used inside the pipeline), this store opens its own short-lived contexts so a monitoring agent can poll it from a background loop.

Methods

Task<IReadOnlyList<SagaSummary>> ListAsync(string? sagaType = null, SagaStatus? status = null, int maxCount = 100, CancellationToken cancellationToken = default(CancellationToken))

List saga instances, newest-updated first, optionally filtered by type and/or status.

Task<SagaCounts> CountAsync(CancellationToken cancellationToken = default(CancellationToken))

Aggregate counts grouped by status across all saga types.

ISagaRepository

public interface ISagaRepository

Persists saga instances on the command’s shared DbContext, so a saga’s state save commits atomically with the outbox/scheduler rows it produced. Lookups track the entity, so the optimistic Version concurrency token is enforced on save.

Methods

Task<SagaRecord?> FindAsync(string sagaType, string correlationKey, Guid? tenantId, CancellationToken cancellationToken = default(CancellationToken))

Find the live instance for a correlation within a tenant (tracked), or null.

Task<SagaRecord?> FindByIdAsync(string sagaType, Guid sagaId, CancellationToken cancellationToken = default(CancellationToken))

Find an instance by id (tracked), or null.

void Add(SagaRecord saga)

Stage a new instance (insert).

void Update(SagaRecord saga)

Stage an update to a tracked instance (the concurrency token guards the write).

SagaCounts

public sealed record SagaCounts : IEquatable<SagaCounts>

Aggregate saga counts grouped by status, for health tiles and KPI cards.

Constructors

SagaCounts(long Active, long Completed, long Faulted)

Aggregate saga counts grouped by status, for health tiles and KPI cards.

Properties

long Active { get; init; }

Live instances still reacting to messages/timeouts.

long Completed { get; init; }

Instances that finished normally.

long Faulted { get; init; }

Instances that failed past their retry budget (left for inspection).

SagaSummary

public sealed record SagaSummary : IEquatable<SagaSummary>

A read-only projection of a SagaRecord for operator dashboards (no state payload).

Constructors

SagaSummary(Guid SagaId, string SagaType, string CorrelationKey, SagaStatus Status, string? CurrentState, Guid? TenantId, int Version, DateTimeOffset CreatedAt, DateTimeOffset UpdatedAt)

A read-only projection of a SagaRecord for operator dashboards (no state payload).

Properties

DateTimeOffset CreatedAt { get; init; }

When the instance started.

DateTimeOffset UpdatedAt { get; init; }

When the instance last transitioned.

Guid SagaId { get; init; }

Instance id.

Guid? TenantId { get; init; }

Owning tenant, or null for global.

SagaStatus Status { get; init; }

Lifecycle status (Active/Completed/Faulted).

int Version { get; init; }

Optimistic-concurrency token (a proxy for how many messages the saga has handled).

string CorrelationKey { get; init; }

Canonical correlation value.

string SagaType { get; init; }

Stable saga type name.

string? CurrentState { get; init; }

Declarative-DSL state name, or null for imperative sagas.

Nuvora.Nexus.Relay.Sagas.Runtime

ISagaCoordinator

public interface ISagaCoordinator

Drives saga transitions. ISagaCoordinator.DeliverAsync is called from a saga trigger (an integration event handler) inside the inbox’s transaction; ISagaCoordinator.DeliverTimeoutAsync from the scheduler’s saga-timeout dispatcher inside its own transaction. Both load-or-create the instance, run the transition, flush side effects (outbox/scheduler) and stage the state save — all on the ambient transaction, so a reaction is atomic.

Methods

Task DeliverAsync(Type sagaType, IIntegrationEvent integrationEvent, CancellationToken cancellationToken)

Deliver an integration event to the saga of the given type.

Task DeliverTimeoutAsync(string sagaTypeName, Guid sagaId, string timeoutTypeName, string payloadJson, CancellationToken cancellationToken)

Deliver a fired timeout back to a specific saga instance.

ISagaInvoker

public interface ISagaInvoker

Non-generic facade over a saga type, so the coordinator can drive any saga without being generic. One singleton per registered saga type.

Properties

IReadOnlyCollection<Type> IntegrationEventTypes { get; }

Integration-event types that correlate to this saga (routed via the inbox).

Type SagaType { get; }
string SagaTypeName { get; }

Methods

Task<SagaInvocationResult> InvokeAsync(string stateJson, object message, SagaExecutionContext context, CancellationToken cancellationToken)

Runs the transition for message on a fresh instance hydrated from stateJson; side effects are buffered on context.

Type? ResolveHandledType(string typeName)

Resolves a handled message/timeout type by its full name (for timeout delivery).

bool IsStartTrigger(Type eventType)

Whether the event type starts a new saga instance.

bool TryCorrelate(IIntegrationEvent integrationEvent, out string key)

Computes the correlation key for an event, or false if this saga does not handle it.

string NewState()

Serialized initial state for a new instance.

ISagaRegistry

public interface ISagaRegistry

Indexes the registered saga invokers by type, type name and handled event type.

Methods

IReadOnlyList<ISagaInvoker> SagasHandling(Type eventType)

All sagas that correlate the given integration-event type (usually one).

ISagaInvoker For(Type sagaType)
ISagaInvoker ForName(string sagaTypeName)

RoutingSlipEntry

public sealed class RoutingSlipEntry

One entry in a saga’s persisted routing-slip itinerary: the stable type name and serialized payload of the compensating command recorded for a completed forward leg. Stored as a JSON array on relay_sagas.itinerary in forward order; replayed in reverse on rollback.

Properties

string Payload { get; set; }
string Type { get; set; }

SagaCoordinator

public sealed class SagaCoordinator : ISagaCoordinator

Default ISagaCoordinator. Resolve scoped, inside the ambient transaction.

Constructors

SagaCoordinator(ISagaRegistry registry, ISagaRepository repository, IScheduler scheduler, IIntegrationEventBus integrationBus, IScheduledMessageSerializer serializer, ISagaTenantProvider tenant, IOptions<SagaOptions> options, TimeProvider timeProvider, ILogger<SagaCoordinator> logger)

Methods

Task DeliverAsync(Type sagaType, IIntegrationEvent integrationEvent, CancellationToken cancellationToken)

Deliver an integration event to the saga of the given type.

Task DeliverTimeoutAsync(string sagaTypeName, Guid sagaId, string timeoutTypeName, string payloadJson, CancellationToken cancellationToken)

Deliver a fired timeout back to a specific saga instance.

SagaInvocationResult

public sealed record SagaInvocationResult : IEquatable<SagaInvocationResult>

Result of running one saga transition: the new serialized state and lifecycle flags.

Constructors

SagaInvocationResult(string State, string? CurrentState, bool Completed)

Result of running one saga transition: the new serialized state and lifecycle flags.

Properties

bool Completed { get; init; }
string State { get; init; }
string? CurrentState { get; init; }

SagaInvoker<TSaga, TState>

public sealed class SagaInvoker<TSaga, TState> : ISagaInvoker where TSaga : Saga<TState>, new() where TState : class, ISagaState, new()

Generic implementation of ISagaInvoker for a concrete saga type.

Constructors

SagaInvoker()

Properties

IReadOnlyCollection<Type> IntegrationEventTypes { get; }

Integration-event types that correlate to this saga (routed via the inbox).

Type SagaType { get; }
string SagaTypeName { get; }

Methods

Task<SagaInvocationResult> InvokeAsync(string stateJson, object message, SagaExecutionContext context, CancellationToken cancellationToken)

Runs the transition for message on a fresh instance hydrated from stateJson; side effects are buffered on context.

Type? ResolveHandledType(string typeName)

Resolves a handled message/timeout type by its full name (for timeout delivery).

bool IsStartTrigger(Type eventType)

Whether the event type starts a new saga instance.

bool TryCorrelate(IIntegrationEvent integrationEvent, out string key)

Computes the correlation key for an event, or false if this saga does not handle it.

string NewState()

Serialized initial state for a new instance.

SagaRegistry

public sealed class SagaRegistry : ISagaRegistry

Default registry built from all registered ISagaInvoker singletons.

Constructors

SagaRegistry(IEnumerable<ISagaInvoker> invokers)

Methods

IReadOnlyList<ISagaInvoker> SagasHandling(Type eventType)

All sagas that correlate the given integration-event type (usually one).

ISagaInvoker For(Type sagaType)
ISagaInvoker ForName(string sagaTypeName)

Nuvora.Nexus.Relay.Sagas.StateMachine

Event<TEvent>

public sealed class Event<TEvent> where TEvent : IIntegrationEvent

A correlated integration event a StateMachineSaga reacts to. Wraps the correlation expression that maps an event instance to its saga’s correlation key; this is the same metadata the imperative StartedBy/Handle overloads capture, so a state machine routes through the existing inbox/registry path unchanged.

Constructors

Event(Func<TEvent, object> correlate)

EventActivityBinder

public abstract class EventActivityBinder

Non-generic view of an EventActivityBinder so Initially/During/ DuringAny can collect binders for heterogeneous message types. External code cannot derive from it (internal constructor); use When(...) to obtain one.

EventActivityBinder<TMessage>

public sealed class EventActivityBinder<TMessage> : EventActivityBinder

Fluent builder for the steps a state machine runs when a given event (or timeout) is handled in a given state. Each method records an activity and returns this; the recorded steps compile down to the imperative engine’s side-effect helpers, so both authoring styles share one execution path.

Methods

EventActivityBinder<TMessage> CancelTimeouts()

Cancel all pending timeouts for this saga.

EventActivityBinder<TMessage> Compensate()

Roll the routing slip back: replay every recorded compensation in reverse order.

EventActivityBinder<TMessage> Compensate(Func<TMessage, ICommand> compensation)

Record the compensating command for the forward leg just performed (Courier-style routing slip). It is appended to the saga’s persisted itinerary; if the slip is later rolled back with EventActivityBinder.Compensate the recorded compensations replay in reverse order.

EventActivityBinder<TMessage> Finalize()

Complete the saga; later messages for this correlation are ignored.

EventActivityBinder<TMessage> Publish(Func<TMessage, IIntegrationEvent> factory)

Publish an integration event (staged on the outbox).

EventActivityBinder<TMessage> Schedule<TTimeout>(Timeout<TTimeout> timeout, TimeSpan delay, Func<TMessage, TTimeout> payload)

Request timeout back to the saga after delay.

EventActivityBinder<TMessage> Send(Func<TMessage, ICommand> factory)

Send a command (scheduled for immediate, reliable delivery).

EventActivityBinder<TMessage> Then(Action<TMessage> action)

Run a synchronous instance action (reads/writes State).

EventActivityBinder<TMessage> Then(Func<TMessage, CancellationToken, Task> action)

Run an asynchronous instance action (reads/writes State).

EventActivityBinder<TMessage> TransitionTo(MachineState state)

Transition to state (persisted as the saga’s current state).

MachineState

public sealed class MachineState

A named state in a StateMachineSaga. The name is persisted in relay_sagas.current_state (the same column the imperative engine’s TransitionTo writes), so it must stay stable across deployments. The implicit “initial” state is the absence of a name (current_state is null); declare reachable states explicitly and transition into them.

Named MachineState rather than State because Saga.State (the saga’s data payload) already occupies that identifier on the base class.

Constructors

MachineState(string name)

Properties

string Name { get; }

The persisted state name.

Methods

override string ToString()

Returns a string that represents the current object.

StateMachineSaga<TState>

public abstract class StateMachineSaga<TState> : Saga<TState> where TState : class, ISagaState, new()

Declarative, state-machine flavour of Saga. Declare the saga’s MachineStates, Events and Timeouts as properties (constructed inline), then describe transitions in StateMachineSaga.DefineStateMachine with Initially/During/DuringAny + When(e).Then(...).Publish(...).Send(...).Schedule(...).TransitionTo(...).Finalize().

This is pure sugar: StateMachineSaga.DefineStateMachine is translated into the very same SagaConfigurator handlers (one composed handler per message type that guards on the persisted CurrentState) the imperative engine already runs — there is no separate runtime, table or schema change. A message with no matching transition in the current state is ignored.

public sealed class OrderSaga : StateMachineSaga<OrderState>
{
    public MachineState Submitted { get; } = new(nameof(Submitted));
    public Event<OrderPlaced> Placed { get; } = new(e => e.OrderId);
    public Timeout<OrderExpired> Expiry { get; } = new();

    protected override void DefineStateMachine() => Initially(
        When(Placed).Then(e => State.OrderId = e.OrderId).TransitionTo(Submitted));
}

Methods

abstract void DefineStateMachine()

Wire the saga’s transitions (the states/events/timeouts are the declared properties).

override sealed void Configure(ISagaConfigurator<TState> configurator)

Wire up correlation and handlers.

static EventActivityBinder<TEvent> When<TEvent>(Event<TEvent> @event)

Begin a transition for an integration event.

static EventActivityBinder<TTimeout> When<TTimeout>(Timeout<TTimeout> timeout)

Begin a transition for a fired timeout.

void During(MachineState state, params EventActivityBinder[] binders)

Transitions valid while the saga is in state.

void DuringAny(params EventActivityBinder[] binders)

Transitions valid in any state (evaluated only if no state-specific transition matched).

void Initially(params EventActivityBinder[] binders)

Transitions valid from the initial state (these events start a new saga instance).

Timeout<TTimeout>

public sealed class Timeout<TTimeout> where TTimeout : notnull

A schedulable timeout for a StateMachineSaga. Declare one per timeout payload type (public Timeout<OrderExpired> ExpiryDeadline { get; } = new();), request it from an activity with .Schedule(timeout, delay, payload), and react to it with When(timeout). It compiles to the imperative engine’s timeout path (a SagaTimeout scheduler row delivered back via OnTimeout<TTimeout>), so timeouts are correlated by saga id, not a key.

Nuvora.Nexus.Relay.Sagas.Tenancy

ISagaTenantProvider

public interface ISagaTenantProvider

Soft-dependency read of the ambient tenant, used to stamp a new saga’s TenantId without a compile-time reference to the tenancy package. The tenancy package replaces the default with a real bridge; absent tenancy, every saga is global.

Properties

Guid? CurrentTenantId { get; }

NullSagaTenantProvider

public sealed class NullSagaTenantProvider : ISagaTenantProvider

Default no-op provider: sagas are global.

Properties

Guid? CurrentTenantId { get; }

Nuvora.Nexus.Relay.Sagas.Timeouts

SagaTimeoutDispatcher

public sealed class SagaTimeoutDispatcher : IScheduledMessageDispatcher

Delivers a fired saga timeout. Registered with the scheduler for ScheduledDeliveryKind.SagaTimeout; runs the saga transition inside its own unit of work so the state save and any new side effects commit atomically. The scheduler has already re-established the owning tenant on the ambient context.

Constructors

SagaTimeoutDispatcher(IRelayScopeAccessor scopeAccessor, IScheduledMessageSerializer serializer, ILogger<SagaTimeoutDispatcher> logger)

Properties

ScheduledDeliveryKind Kind { get; }

The delivery kind this dispatcher handles.

Methods

Task DispatchAsync(ScheduledMessage message, IServiceProvider scope, CancellationToken cancellationToken)

Deliver the message. scope is a fresh per-message DI scope; the ambient tenant (if any) has already been re-established by the processor. Throwing records a delivery failure (retry/backoff/dead-letter); returning normally marks the message executed.

SagaTimeoutEnvelope

public sealed class SagaTimeoutEnvelope

Payload of a scheduled saga-timeout row: carries the saga type and id so the timeout can be routed back to the right saga instance, plus the inner timeout type + serialized payload.

Properties

Guid SagaId { get; set; }
string CorrelationKey { get; set; }
string Payload { get; set; }
string SagaType { get; set; }
string TimeoutType { get; set; }