CQRS.NET
2.1
A lightweight enterprise framework to write CQRS, event-sourced and micro-service applications in hybrid multi-datacentre, on-premise and Azure environments.
|
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...
Public Member Functions | |
IEnumerable< ISagaEvent< TAuthenticationToken > > | GetUncommittedChanges () |
void | MarkChangesAsCommitted () |
void | LoadFromHistory (IEnumerable< ISagaEvent< TAuthenticationToken >> history) |
Properties | |
Guid | Id [get] |
int | Version [get] |
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.