For most of my applications I use a straight-forward DDD approach, which means separating the layers of the Onion Architecture, decoupling the domain from the infrastructure, etc. Two often-recurring building blocks, the repository and event bus, look like this (simplified).
public interface IRepository<TEntity, TKey>
where TEntity : EntityBase<TKey>
{
void Add(TEntity entity);
}
public interface IEventBus {
void Publish<TEvent>(TEvent @event)
where TEvent : IEvent;
}
Recently, I started looking into CQRS and I recognize a lot of similar patterns, again such as repositories, event & command buses. However, e.g. the repositories in CQRS are not responsible for storing/retrieving entities, but for managing aggregates and constructing event streams.
Now I'm wondering: do both of them work together? Or are they completely different approaches that just share a few common things?