This sample is showing a typical flow of the Event Sourcing pattern with EventStoreDB using CQRS. It uses E-Commerce shopping carts domain.
- .NET 6.0 - https://dotnet.microsoft.com/download/dotnet/6.0.
- Visual Studio 2022, Jetbrains Rider or VSCode.
- Docker - https://docs.docker.com/docker-for-windows/install/.
- Run:
docker-compose up
. - Wait until all Docker containers are up and running.
- Check that you can access each started component the following URLs:
- EventStoreDB: http://localhost:2113/ (use the default user
admin
and passwordchangeit
) - ElasticSearch: http://localhost:9200
- Kibana: http://localhost:5601
- EventStoreDB: http://localhost:2113/ (use the default user
- Open, build and run
ECommerce.sln
solution.- The Swagger UI should be available at: http://localhost:5000/index.html
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 flow example with Command and Query handling,
- App has Swagger and predefined docker-compose to run and play with samples.
- 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 models are rebuilt with eventual consistency using subscribe to all EventStoreDB feature,
- Added class to manage subscriptions: EventStoreDBSubscriptionToAll to handle subscribing to all. It handles checkpointing and simple retries if the connection was dropped. It's run inside the BackgroundWorker that provides the abstraction for starting and disposing hosted service.
- 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. It supports idempotency through "external version" ElasticSearch mechanism. Another (e.g. MongoDB, EntityFramework) can be implemented the same way.
- Added sample of unit testing in
Carts.Tests
: - Added sample of integration testing in
Carts.Api.Tests
- 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,
- Docker useful commands
docker-compose up
- start dockersdocker-compose kill
- to stop running dockers.docker-compose down -v
- to clean stopped dockers.docker ps
- for showing running dockersdocker ps -a
- to show all dockers (also stopped)