• Stars
    star
    97
  • Rank 336,374 (Top 7 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated about 1 year 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