Giter VIP home page Giter VIP logo

commandquery's Introduction

CommandQuery

build CodeFactor

CommandQuery CommandQuery.Abstractions CommandQuery.Client

CommandQuery.AspNetCore CommandQuery.AWSLambda CommandQuery.AzureFunctions CommandQuery.GoogleCloudFunctions CommandQuery.AspNet.WebApi

Content

Introduction

Command Query Separation (CQS) for .NET and C#

  • Build services that separate the responsibility of commands and queries
  • Focus on implementing the handlers for commands and queries
  • Create APIs with less boilerplate code

Available for:

🌐 ASP.NET Core
⚑ AWS Lambda
⚑ Azure Functions
⚑ Google Cloud Functions
🌐 ASP.NET Web API 2

Command Query Separation?

Queries: Return a result and do not change the observable state of the system (are free of side effects).

Commands: Change the state of a system but do not return a value.

β€” Martin Fowler

In other words:

  • Commands
    • Writes (create, update, delete) data
  • Queries
    • Reads and returns data

The traditional approach that commands do not return a value is a bit inconvenient.

CommandQuery has a pragmatic take and supports both commands with and without result πŸ‘

Packages

CommandQuery βš™οΈ

NuGet NuGet

Command Query Separation for .NET

CommandQuery.AspNetCore 🌐

NuGet NuGet

Command Query Separation for ASP.NET Core

CommandQuery.AWSLambda ⚑

NuGet NuGet

Command Query Separation for AWS Lambda

CommandQuery.AzureFunctions ⚑

NuGet NuGet

Command Query Separation for Azure Functions

CommandQuery.GoogleCloudFunctions ⚑

NuGet NuGet

Command Query Separation for Google Cloud Functions

CommandQuery.Client 🧰

NuGet NuGet

Clients for CommandQuery APIs

CommandQuery.AspNet.WebApi 🌐

NuGet NuGet

Command Query Separation for ASP.NET Web API 2

β›” This package is no longer maintained and new versions will not be published

Upgrading

⬆️ Upgrading from version 1.0.0 to 2.0.0

Upgrade command/query handlers:

  • Upgrade the project target framework from net461 to netstandard2.0 or greater
  • Add a CancellationToken parameter to the HandleAsync methods in classes that implement ICommandHandler<TCommand>, ICommandHandler<TCommand, TResult> and IQueryHandler<TQuery, TResult>

Upgrade AspNet.WebApi:

  • Migrate from CommandQuery.AspNet.WebApi to CommandQuery.AspNetCore

Upgrade AspNetCore:

  • Consider to upgrade the project target framework to netcoreapp3.1 or net5.0
  • Consider to use the extension methods AddCommandControllers and AddQueryControllers in Startup.cs

Upgrade AWSLambda:

  • Upgrade the project target framework to netcoreapp3.1
  • Change the method invocation on CommandFunction and QueryFunction from Handle to HandleAsync
  • Change the argument on HandleAsync methods from ILambdaContext to ILambdaLogger
  • Consider to use the extension methods AddCommandFunction and AddQueryFunction on IServiceCollection
  • Consider to use the JsonSerializerOptions constructor argument in CommandFunction and QueryFunction to configure JSON serialization/deserialization

Upgrade AzureFunctions:

  • Upgrade the project target framework to netcoreapp3.1 or net5.0
  • Change the method invocation on CommandFunction and QueryFunction from Handle to HandleAsync
  • Consider to use the extension methods AddCommandControllers and AddQueryControllers in Startup.cs/Program.cs
  • Consider to use the CancellationToken argument on HandleAsync methods in netcoreapp3.1 projects
  • Consider to use the JsonSerializerSettings/JsonSerializerOptions constructor argument in CommandFunction and QueryFunction to configure JSON serialization/deserialization

Upgrade Client:

  • Change the method invocation on CommandClient and QueryClient from Post to PostAsync and from Get to GetAsync
  • Consider to use the AddHttpClient extension method on IServiceCollection to create the CommandClient and QueryClient (see sample)
  • Consider to use the CancellationToken argument to methods in CommandClient and QueryClient

Validation:

  • Consider to use the AssertConfigurationIsValid method on CommandProcessor and QueryProcessor to validate handler and type configuration

Acknowledgements

Inspired by Steven van Deursen blog posts:

commandquery's People

Contributors

hlaueriksson 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.