Sample is showing the typical flow of the Event Sourcing app with EventStoreDB.
- Install git - https://git-scm.com/downloads.
- Install .NET 6.0 - https://dotnet.microsoft.com/download/dotnet/6.0.
- Install Visual Studio 2022, Rider or VSCode.
- Install docker - https://docs.docker.com/engine/install/.
- Open
ECommerce.sln
solution.
- Go to docker and run:
docker-compose up
. - Wait until all dockers got are downloaded and running.
- You should automatically get:
- EventStoreDB UI (for event store): http://localhost:2113/
- Postgres DB running (for read models)
- PG Admin - IDE for postgres. Available at: http://localhost:5050.
- Login:
[email protected]
, Password:admin
- To connect to server Use host:
postgres
, user:postgres
, password:Password12!
- Login:
- Open, build and run
ECommerce.sln
solution.- Swagger should be available at: http://localhost:5000/index.html
It uses:
- CQRS with MediatR,
- Stores events from Aggregate method results to EventStoreDB,
- Builds read models using Subscription to
$all
. - Read models are stored as Marten documents.
- App has Swagger and predefined docker-compose to run and play with samples.
- Most of the write model infrastructure was reused from other samples,
- Added new project
Core.EventStoreDB
for specific EventStoreDB code, - Added EventStoreDBRepository repository to load and store aggregate state,
- Added separate 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
- Read models are rebuilt with eventual consistency using subscribe to all EventStoreDB feature,
- Uses hosted service EventStoreDBSubscriptionToAll to handle subscribing to all. It handles checkpointing and simple retries if the connection was dropped.
- Uses checkpointing to EventStoreDB stream with EventStoreDBSubscriptionCheckpointRepository and dummy in-memory checkpointer InMemorySubscriptionCheckpointRepository,
- Uses MartenExternalProjection as a sample how to project with
left-fold
into external storage. Another (e.g. ElasticSearch, EntityFramework) can be implemented the same way.
- Added sample of unit testing in
Carts.Tests
: - Added sample of integration testing in
Carts.Api.Tests
- Uses EventTypeMapper class to allow both convention-based mapping (by the .NET type name) and custom to handle event versioning,
- Uses 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)