Git Product home page Git Product logo

eventsourcingsamplewithmediatr's Introduction

Event Sourcing Sample With CQRS and MediatR

.Net Core 3.0, PostgreSql, EntityFrameworkCore, Xunit, MiniCover, Docker ,Swagger , ProblemDetails, CorrelationId, Prometheus

Description

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

Requirements

  • .Net Core >= 3.0
  • PostgreSql
  • Docker

Features

Framework
Storage
Data Access
Integration testing
Logging
Metrics
Api Documentation
Test Coverage

Running the API

Development

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

Swagger documentation will be available on route:

http://localhost:5000/swagger

Testing

To run tests:

dotnet test ./tests/EventSourcingSampleWithCQRSandMediatr.Tests/EventSourcingSampleWithCQRSandMediatr.Tests.csproj

To run unit and integration tests with script:

scripts/tests.sh

Test Coverage

scripts/coverage.sh

Coverage file can be found in coverage-html/index.html file

Set up environment

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.

*To configure PostgreSql db:

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,
  }

To configure InMemory storage:

appsettings.json

 "Db": {
    "UseMemoryDb": true
  }

*To configure db docker-compose.yml:

docker-compose.yml

  environment:
	Db__ConnectionString: 'Your Connection string'
	Db__UseMemoryDb: 'your choice true/false'

*TODO-Nice to have list:

  • Use Marten as event sourcing tool
  • Add more statistics like injuries and player substitution
  • Add more business validation

eventsourcingsamplewithmediatr's People

Contributors

ozanerdogan90 avatar

Stargazers

Jonas avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.