CQRS.NET  4.0
A lightweight enterprise Function as a Service (FaaS) framework to write function based serverless and micro-service applications in hybrid multi-datacentre, on-premise and Azure environments.
Cqrs.Domain.ISaga< TAuthenticationToken > Interface Template Reference

An independent component that reacts to domain IEvent<TAuthenticationToken> in a cross-IAggregateRoot<TAuthenticationToken>, eventually consistent manner. Time can also be a trigger. A Saga<TAuthenticationToken> can sometimes be purely reactive, and sometimes represent workflows. More...

+ Inheritance diagram for Cqrs.Domain.ISaga< TAuthenticationToken >:

Public Member Functions

IEnumerable< ISagaEvent< TAuthenticationToken > > GetUncommittedChanges ()
 Get all applied changes that haven't yet been committed. More...
 
void MarkChangesAsCommitted ()
 Mark all applied changes as committed, increment Version and flush the internal collection of changes. More...
 
void LoadFromHistory (IEnumerable< ISagaEvent< TAuthenticationToken >> history)
 Apply all the events in history using event replay to this instance. More...
 
IEnumerable< ICommand< TAuthenticationToken > > GetUnpublishedCommands ()
 Get all pending commands that haven't yet been published yet. More...
 
void MarkCommandsAsPublished ()
 Mark all published commands as published and flush the internal collection of commands. More...
 

Properties

Guid Id [get]
 The identifier of the ISaga<TAuthenticationToken>. More...
 
int Version [get]
 The current version of this ISaga<TAuthenticationToken>. More...
 

Detailed Description

An independent component that reacts to domain IEvent<TAuthenticationToken> in a cross-IAggregateRoot<TAuthenticationToken>, eventually consistent manner. Time can also be a trigger. A Saga<TAuthenticationToken> can sometimes be purely reactive, and sometimes represent workflows.

From an implementation perspective, a Saga<TAuthenticationToken> is a state machine that is driven forward by incoming IEvent<TAuthenticationToken> (which may come from many AggregateRoot<TAuthenticationToken> or other Saga<TAuthenticationToken>). Some states will have side effects, such as sending ICommand<TAuthenticationToken>, talking to external web services, or sending emails.

Isn't a Saga<TAuthenticationToken> just leaked domain logic? No. A Saga<TAuthenticationToken> can doing things that no individual AggregateRoot<TAuthenticationToken> can sensibly do. Thus, it's not a logic leak since the logic didn't belong in an AggregateRoot<TAuthenticationToken> anyway. Furthermore, we're not breaking encapsulation in any way, since Saga<TAuthenticationToken> operate with ICommand<TAuthenticationToken> and IEvent<TAuthenticationToken>, which are part of the public API.

How can I make my Saga<TAuthenticationToken> react to an IEvent<TAuthenticationToken> that did not happen? The Saga<TAuthenticationToken>, besides reacting to domain IEvent<TAuthenticationToken>, can be "woken up" by recurrent internal alarms. Implementing such alarms is easy. See cron in Unix, or triggered WebJobs in Azure for examples.

How does the Saga<TAuthenticationToken> interact with the write side? By sending an ICommand<TAuthenticationToken> to it.