For most of my applications, I use the direct DDD approach, which means separating the levels of Onion Architecture, separating the domain from the infrastructure, etc. Two frequently repeated building blocks, a storage and an event bus, are as follows (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;
}
I recently started studying CQRS and found many similar patterns, such as repositories, events, and command buses. However, for example, repositories in CQRS are not responsible for storing / retrieving objects, but for managing aggregates and building event flows.
Now I wonder: do they both work together? Or are these completely different approaches, in which there are several common features?