I'm currently trying to define certain base classes & interfaces to use them in DDD & CQRS projects, however I'm struggling with the definition of aggregates and aggregate roots.
The blue book tells us that...
- An aggregate is a cluster of objects
- Each aggregate has a aggregate root
- The aggregate root is a specific entity and the only object other parts of the application can reference to.
For this, I made the following classes / interfaces:
Entity
public interface IEntity {
TKey Key { get; set; }
}
public abstract class EntityBase : IEntity {
// key stuff, equality comparer..
}
Aggregate Root
public interface IAggregateRoot : IEntity
{
}
Repository
public interface IRepository
where TAggregate : IAggregate
where TRoot : IAggregateRoot
{
TRoot Root { get; set; }
void Add(TAggregate aggregate);
}
Now, did I understood this correctly? How might a aggregate interface look like then?
public interface IAggregate
where TRoot : IAggregateRoot
{
}
I tried to find some references and in a CQRS framework I found the following implementation: (Does CQRS differ so much from DDD? I thought it's pretty much the same when not applying event sourcing)
public abstract class Entity where TAggregateRoot
: AggregateRoot
{
}