Giter Club home page Giter Club logo

cqrs's Introduction

CQRS

Our implementation of query and command responsability segregation (CQRS).

Getting Started

Install nuget package to your awesome project.

Full Version NuGet NuGet Install
PoweredSoft.CQRS.Abstractions NuGet PM> Install-Package PoweredSoft.CQRS.Abstractions
PoweredSoft.CQRS NuGet PM> Install-Package PoweredSoft.CQRS
PoweredSoft.CQRS.FluentValidation NuGet PM> Install-Package PoweredSoft.CQRS.FluentValidation
PoweredSoft.CQRS.AspNetCore.Abstractions NuGet PM> Install-Package PoweredSoft.CQRS.AspNetCore.Abstractions
PoweredSoft.CQRS.AspNetCore NuGet PM> Install-Package PoweredSoft.CQRS.AspNetCore
PoweredSoft.CQRS.GraphQL.HotChocolate NuGet PM> Install-Package PoweredSoft.CQRS.GraphQL.HotChocolate

Sample of startup code for aspnetcore MVC

public void ConfigureServices(IServiceCollection services)
{
    // make sure to add your queries and commands before the .AddPoweredSoftQueries and .AddPoweredSoftCommands
    AddQueries(services);
    AddCommands(services);

    // adds the non related to aspnet core features.
    services.AddPoweredSoftCQRS();
    
    services
        .AddControllers()
        .AddPoweredSoftQueries() // adds queries to aspnetcore mvc.(you can make it configurable to load balance only commands on a instance)
        .AddPoweredSoftCommands() // adds commands to aspnetcore mvc. (you can make it configurable to load balance only commands on a instance)
        .AddFluentValidation();

    // enabling gql.
    services
        .AddGraphQLServer()
        .AddProjections()
        .AddQueryType(d => d.Name("Query"))
        .AddPoweredSoftQueries()
        .AddPoweredSoftDynamicQueries()
        .AddMutationType(d => d.Name("Mutation"))
        .AddPoweredSoftMutations();

    services.AddSwaggerGen();
}

Example how to add your queries and commands.

private void AddCommands(IServiceCollection services)
{
    services.AddCommand<CreatePersonCommand, CreatePersonCommandHandler>();
    services.AddTransient<IValidator<CreatePersonCommand>, CreatePersonCommandValidator>();

    services.AddCommand<EchoCommand, string, EchoCommandHandler>();
    services.AddTransient<IValidator<EchoCommand>, EchoCommandValidator>();
}

private void AddQueries(IServiceCollection services)
{
    services.AddQuery<PersonQuery, IQueryable<Person>, PersonQueryHandler>();
}

Fluent Validation

We use fluent validation in all of our projects, but we don't want it to be enforced.

If you install. PoweredSoft.CQRS.FluentValidation you can use this way of registrating your commands.

public void ConfigureServices(IServiceCollection services) 
{
    // without Package.
    services.AddCommand<EchoCommand, string, EchoCommandHandler>();
    services.AddTransient<IValidator<EchoCommand>, EchoCommandValidator>();
}

public void ConfigureServices(IServiceCollection services) 
{
    // with PoweredSoft.CQRS.FluentValidation package.
    services.AddCommandWithValidator<EchoCommand, string, EchoCommandHandler, EchoCommandValidator>();
}

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.