Giter Site home page Giter Site logo

simplecqrs's Introduction

Teast.SimpleCQRS

This is a simple "CQRS"/EventStore implementation that can be used to simplify the boiling plates when building such solutions.

Nuget package

To build nuget package and publish it you can do following commands:

dotnet pack src/SimpleCQRS/
dotnet nuget push src/SimpleCQRS/bin/Release/Teast.SimpleCQRS.0.0.1-preview3.nupkg --api-key <redacted> --source nuget.org

Implementation

The idea is to have Command objects that drives changes to your entity. One implementation is to create an CommandHandler class that can handle your Commands and that uses your Aggregate to generate an corresponding Event object.

Difference between Command and Event

The main different between this two objects is that a Command should be validated and can be rejected while an Event should never be validated and instead always be applied. A Command that is accepted should generate an Event and the Event is the one that should be stored in your data storage and then later on read from data storage when you re-play your entity through an Aggregate

Difference between snapshot and projection

a projection should always represent latest state of your entity while a snapshot can be from any state of your entity.

IStorage

This interface is the glue between Simple.CQRS and your data storage. When Repository needs to fetch events, snapshot, versions, etc from the data storage it will use an object that implements this interface.

Repository

This abstract class will take care of extracting changes from an existing Aggregate for saving to data storage or to create an Aggregate based of data fetched from IStorage.

Aggregate

Aggregate handles creation of events and to load events.

Event

Represents an change to your entity. All changes that you support should inherit from Event

Data

This class represents an snapshot (or projection) of your entity. It is possible to use SimpleCQRS without having an dedicated snapshot class.

Samples

UserApi

This WebApi demonstrates how you can use SimpleCQRS with Entityframework Core as database storage.

The entity in this example is an User entity where you can change the user's name, email or age through commands. You can also create an user through the CreateCommand.

The Data object in this example is used as an projection instead of an snapshot object. That simplifies the "GET" calls where I can read directly from the projection table.

simplecqrs's People

Contributors

teast avatar

Watchers

 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.