Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Github Sponsors blog blog

E-Commerce sample of Event Sourcing with EventStoreDB

Sample is showing the typical flow of the Event Sourcing app with EventStoreDB.

Prerequisites

  1. Install git - https://git-scm.com/downloads.
  2. Install .NET 6.0 - https://dotnet.microsoft.com/download/dotnet/6.0.
  3. Install Visual Studio 2022, Rider or VSCode.
  4. Install docker - https://docs.docker.com/engine/install/.
  5. Open ECommerce.sln solution.

Running

  1. Go to docker and run: docker-compose up.
  2. Wait until all dockers got are downloaded and running.
  3. 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!
  4. Open, build and run ECommerce.sln solution.

Overview

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.

Write Model

  • 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 Model

Tests

Other

Trivia

  1. Docker useful commands
    • docker-compose up - start dockers
    • docker-compose kill - to stop running dockers.
    • docker-compose down -v - to clean stopped dockers.
    • docker ps - for showing running dockers
    • docker ps -a - to show all dockers (also stopped)