Please see the code here: https://github.com/vkhorikov/DddInAction/blob/master/DddInPractice.Logic/Common/AggregateRoot.cs and specifically:
using System.Collections.Generic; namespace DddInPractice.Logic.Common { public abstract class AggregateRoot { private readonly List<IDomainEvent> _domainEvents = new List<IDomainEvent>(); public virtual IReadOnlyList<IDomainEvent> DomainEvents => _domainEvents; protected virtual void AddDomainEvent(IDomainEvent newEvent) { _domainEvents.Add(newEvent); } public virtual void ClearEvents() { _domainEvents.Clear(); } } }
I am debating whether to use this class in my project. I like the idea because it encapsulates Domain Events. If I use it then all Aggregate Root classes will derive from it. Alternatively I could use a marker interface like this (which all Aggregate Roots will implement):
public interface IAggregateRoot { }
Should I:
1) Create the base class or 2) Create the interface or 3) Do neither
I thike the idea of marking my Aggregate Roots.