Class AggregateRoot<TAuthenticationToken>
A larger unit of encapsulation than just a class. Every transaction is scoped to a single aggregate. The lifetimes of the components of an aggregate are bounded by the lifetime of the entire aggregate.
Concretely, an aggregate will handle commands, apply events, and have a state model encapsulated within it that allows it to implement the required command validation, thus upholding the invariants (business rules) of the aggregate.
Inheritance
Inherited Members
Namespace: Cqrs.Domain
Assembly: Cqrs.dll
Syntax
[Serializable]
public abstract class AggregateRoot<TAuthenticationToken> : IAggregateRoot<TAuthenticationToken>
Type Parameters
Name | Description |
---|---|
TAuthenticationToken |
Remarks
Why is the use of GUID as IDs a good practice?
Because they are (reasonably) globally unique, and can be generated either by the server or by the client.
Constructors
AggregateRoot()
Instantiates a new instance of AggregateRoot<TAuthenticationToken>.
Declaration
protected AggregateRoot()
Properties
Id
The identifier of this IAggregateRoot<TAuthenticationToken>.
Declaration
[DataMember]
public Guid Id { get; protected set; }
Property Value
Type | Description |
---|---|
System.Guid |
Implements
Version
The current version of this IAggregateRoot<TAuthenticationToken>.
Declaration
[DataMember]
public int Version { get; protected set; }
Property Value
Type | Description |
---|---|
System.Int32 |
Implements
Methods
ApplyChange(IEvent<TAuthenticationToken>)
Call the "Apply" method with a signature matching the provided event
without using event replay to this instance.
Declaration
protected virtual void ApplyChange(IEvent<TAuthenticationToken> event)
Parameters
Type | Name | Description |
---|---|---|
IEvent<TAuthenticationToken> | event |
Remarks
This means a method named "Apply", with return type void and one parameter must exist to be applied.
If no method exists, nothing is applied
The parameter type must match exactly the System.Type of the provided event
.
GetUncommittedChanges()
Get all applied changes that haven't yet been committed.
Declaration
public IEnumerable<IEvent<TAuthenticationToken>> GetUncommittedChanges()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>> |
Implements
LoadFromHistory(IEnumerable<IEvent<TAuthenticationToken>>)
Apply all the IEvent<TAuthenticationToken> in history
using event replay to this instance.
Declaration
public virtual void LoadFromHistory(IEnumerable<IEvent<TAuthenticationToken>> history)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<IEvent<TAuthenticationToken>> | history |
Implements
MarkChangesAsCommitted()
Mark all applied changes as committed, increment Version and flush the Cqrs.Domain.AggregateRoot`1.Changes.
Declaration
public virtual void MarkChangesAsCommitted()