.Net Core 3.0, PostgreSql, EntityFrameworkCore, Xunit, MiniCover, Docker ,Swagger , ProblemDetails, CorrelationId, Prometheus
This project aims to be an example of event sourcing in .net core.
Case Study: Most common sample of event sourcing is bank account transactions. But in this sample I used a football game as a domain;
- Create a match (requires information like home and away teams info )
- Start the match (requires game id )
- Add score for one team
- Add card to a game statistics
- Add faul to game statistics
- Get score board
- Get game details
All the data is storaged in relevant individual tables in postgreSql database. Event sourcing is handled with cqrs and mediatr patterns.No external tool is used and Marten is planned to use in future
There is a e2e test that covers all the flow .It can be found here
- .Net Core >= 3.0
- PostgreSql
- Docker
To start the application in development mode, run:
dotnet build
cd src\EventSourcingSampleWithCQRSandMediatr
dotnet run
Application will be served on route: http://localhost:5000
To start the application in docker container:
docker-compose up
Docker will spin up application, postgreSql container and PgAdmin to manage database and will be served on route : http://localhost:5001
Swagger documentation will be available on route:
http://localhost:5000/swagger
To run tests:
dotnet test ./tests/EventSourcingSampleWithCQRSandMediatr.Tests/EventSourcingSampleWithCQRSandMediatr.Tests.csproj
To run unit and integration tests with script:
scripts/tests.sh
scripts/coverage.sh
Coverage file can be found in coverage-html/index.html file
Keys and the secrets are defined in user secret file. More information can be found .net core user secrets This application uses "8c43a081-db6b-43eb-8376-df1651b2d72a" as secret key id.
Application uses InMemory database for local development and PostgreSql is also configurable.To configure: Connection string needs to be defined in appsettings.json
"Db": {
"ConnectionString": "Your connection string"
"UseMemoryDb": false,
}
appsettings.json
"Db": {
"UseMemoryDb": true
}
docker-compose.yml
environment:
Db__ConnectionString: 'Your Connection string'
Db__UseMemoryDb: 'your choice true/false'
- Use Marten as event sourcing tool
- Add more statistics like injuries and player substitution
- Add more business validation