Sample is showing the typical flow of the Event Sourcing app with EventStoreDB.
- Install git - https://git-scm.com/downloads.
- Install .NET Core 6.0 - https://dotnet.microsoft.com/download/dotnet/6.0.
- Install Visual Studio 2022, Rider or VSCode.
- Install docker - https://docs.docker.com/docker-for-windows/install/.
- Open
ECommerce.slnsolution.
- 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:
admin@pgadmin.org, Password:admin - To connect to server Use host:
postgres, user:postgres, password:Password12!
- Login:
- Open, build and run
ECommerce.slnsolution.- 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.EventStoreDBfor 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,
- 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 MartenExternalProjection as a sample how to project with
left-foldinto 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
- Added EventTypeMapper class to allow both convention-based mapping (by the .NET type name) and custom to handle event versioning,
- Added 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)