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.
Cqrs.Domain.Saga< TAuthenticationToken > Class 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.Saga< TAuthenticationToken >:

Public Member Functions

IEnumerable< ISagaEvent< TAuthenticationToken > > GetUncommittedChanges ()
 
virtual void MarkChangesAsCommitted ()
 
virtual void LoadFromHistory (IEnumerable< ISagaEvent< TAuthenticationToken >> history)
 

Protected Member Functions

 Saga ()
 A constructor for the Cqrs.Domain.Factories.IAggregateFactory More...
 
 Saga (IDependencyResolver dependencyResolver, ILogger logger)
 A constructor for the Cqrs.Domain.Factories.IAggregateFactory More...
 
 Saga (IDependencyResolver dependencyResolver, ILogger logger, Guid rsn)
 
virtual void ApplyChange (ISagaEvent< TAuthenticationToken > @event)
 
virtual void ApplyChange (IEvent< TAuthenticationToken > @event)
 

Properties

Guid Rsn [get]
 
Guid Id [get, protected set]
 
int Version [get, protected set]
 
ICommandPublisher< TAuthenticationToken > CommandPublisher [get]
 
IDependencyResolver DependencyResolver [get]
 
ILogger Logger [get]
 
- Properties inherited from Cqrs.Domain.ISaga< TAuthenticationToken >
Guid Id [get]
 
int Version [get]
 

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.