• Stars
    star
    97
  • Rank 348,505 (Top 7 %)
  • Language
    C#
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command Query Separation for 🌐ASP.NET Core ⚑AWS Lambda ⚑Azure Functions ⚑Google Cloud Functions

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:

More Repositories

1

puppeteer-sharp-contrib

Contributions to the Headless Chrome .NET API 🌐πŸ§ͺ
C#
77
star
2

GEmojiSharp

:octocat: GitHub Emoji for C#, ASP.NET Core and Blazor, dotnet tool for the terminal and PowerToys Run plugin
C#
56
star
3

jekyll-url-shortener

βœ‚οΈπŸ”— This is a template repository for making URL Shorteners with Jekyll and GitHub Pages. Create short URLs that can be easily shared, tweeted, or emailed to friends.
Ruby
39
star
4

awesome-powertoys-run-plugins

πŸ—‚οΈπŸ”Ž Delightful PowerToys Run plugins πŸ”Œ
38
star
5

LoFuUnit

Unit Testing with Local Functions 🐯
C#
28
star
6

programmering-for-barn

En lista med resurser pΓ₯ svenska, fΓΆr att lΓ€ra barn programmering πŸ’» πŸ‘¦ πŸ‘§ πŸ‡ΈπŸ‡ͺ
23
star
7

dotnet-azure-naming

A .NET tool that helps with naming conventions of azure resources
C#
19
star
8

ConductOfCode

Code examples for the blog
C#
17
star
9

github-emoji

:octocat: GitHub Emoji
JavaScript
15
star
10

jamstack-cms

A JAMstack experiment with a Headless CMS
HTML
12
star
11

playwright-dotnet-contrib

Contributions to Playwright for .NET 🎭πŸ§ͺ
C#
11
star
12

jamstack

A JAMstack experiment
HTML
5
star
13

full-stack-csharp

Full Stack C# with Blazor, Azure Functions
C#
3
star
14

BabyMoz

A series of educational apps for children on the Android platform
Java
3
star
15

AzureFunctionsInfo

Information gathered on Azure Functions by executing Azure Functions ⚑️
C#
2
star
16

hoffenkloffen.com

The Hoffenkloffen website
HTML
2
star
17

henrik.laueriksson.com

The source of henrik.laueriksson.com
HTML
2
star
18

LoneWolf

LoneWolf is a series of books/games on the Android platform
Java
1
star
19

Radio

Android radio player for archived episodes
Java
1
star
20

hackrobat.org

πŸ“ Manifesto for Software Hackrobats
Ruby
1
star
21

latest-functions

Azure Functions for latest online activities
C#
1
star
22

AWSLambdaInfo

Information gathered on AWS Lambda by executing AWS Lambda ⚑️
C#
1
star
23

AreYouMockingMe

Examples of unit test, mock and auto mock frameworks in C#
C#
1
star
24

hlaueriksson.me

βœ‚οΈπŸ”— URL Shortener for projects made by Henrik Lau Eriksson
Ruby
1
star