Todo.CQRS
Todo.CQRS copied to clipboard
CQRS and Event Sourcing sample application and architecture
CQRS + ES + DDD + .NET 5.0
CQRS stands for Command and Query Responsibility Segregation
ES stands for Event Sourcing
DDD stands for Domain Driven Design
Features
- Commands and handlers
- Domain models (Aggregates)
- Aggregate repository
- Event sourcing using EventStore
- Domain events and handlers (Projections)
- Integration events and handlers (Cross module projections)
- Read models
- Query controllers
- Unit of work, Read repository, Write repository
- Auto registration of commands, events and their handlers
- Unit of work for multiple aggregates
- Snapshots, Snapshot repository, Snapshot storage in eventstore db
- Checkpoint, Checkpoint repository, Checkpoint storage in eventstore db
- Class for sequential GUIDs
- Entity tracking for write repository and no tracking for read repository
Notes:
- Inherit domain model with
AggregateRootorSnapshotAggregateRoot<Snapshot>. - Domain model must have a parameterless constructor with a
privateaccess modifier. - Set all setters with
privatemodifier to all properties in the domain model. Domainlayer has no dependencies exceptContractslayer.- All business logic and validation should be written in domain models.
Contractscontain Command and Event classes, no business logic should be written inContracts.- All database updates are done from
EventHandleronly. - Use
IReadRepositoryfor query controllers. - Use sequential Guids
CombGuid.NewGuid()instead ofGuid.NewGuid(). - Use
IUnitOfWorkto update data in event handlers. - Start background processor before starting web app
- AggregateVersion start from 1, where in EventStore event version start from 0.
How to configure Eventstore?
Diagrams:
