Added sample for Event Sourcing with CQRS flow in .NET
Overview
It uses:
- Provides the example of the Aggregate,
- Stores events to EventStoreDB,
- Builds read models using Subscription to
$all
. - Read models are stored as ElasticSearch documents.
- CQRS with MediatR,
- App has Swagger and predefined docker-compose to run and play with samples.
Write Model
- Provides the basic boilerplate together with Core projects,
- EventStoreDBRepository repository to load and store aggregate state,
- IProjection interface to handle the same way stream aggregation and materialised projections,
- Thanks to that added dedicated AggregateStream method for stream aggregation
- See sample Aggregate and base class
Read Model
- Read models are rebuilt with eventual consistency using subscribe to all EventStoreDB feature,
- Added hosted service SubscribeToAllBackgroundWorker to handle subscribing to all. It handles checkpointing and simple retries if the connection was dropped.
- Added ISubscriptionCheckpointRepository for handling Subscription checkpointing.
- Added checkpointing to EventStoreDB stream with EventStoreDBSubscriptionCheckpointRepository and dummy in-memory checkpointer InMemorySubscriptionCheckpointRepository,
- Added ElasticSearchProjection as a sample how to project with
left-fold
into external storage. Another (e.g. MongoDB, EntityFramework) can be implemented the same way.
Tests
- Added sample of unit testing in
Carts.Tests
: - Added sample of integration testing in
Carts.Api.Tests
Other
- EventTypeMapper class to allow both convention-based mapping (by the .NET type name) and custom to handle event versioning,
- StreamNameMapper class for convention-based id (and optional tenant) mapping based on the stream type and module,
- IoC registration helpers for EventStoreDB configuration,