I\'ve been studying on domain driven design in conjunction with domain events. I really like the separations of concerns those events provide. I ran into an issue with the order
Disclaimer: I don't know what I am talking about. ⚠️
As an alternative to raising events in the ShoppingCartService
you could raise events in the OrderRepository
.
As an alternative to queuing domain events in the ShoppingCartService
you could queue them in the Order
aggregate by inheriting from a base class that provides a AddDomainEvent
method.
public class Order : Aggregate
{
public Order(IEnumerable cart, Customer customer)
{
AddDomainEvent(new OrderCreated(cart, customer))
}
}
public abstract class Aggregate
{
private List _domainEvents = new List();
public IReadOnlyCollection DomainEvents => _domainEvents.AsReadOnly();
public void AddDomainEvent(IDomainEvent domainEvent)
{
_domainEvents.Add(domainEvent);
}
}