CommandQuery
CommandQuery copied to clipboard
Command Query Separation for 🌐ASP.NET Core ⚡AWS Lambda ⚡Azure Functions ⚡Google Cloud Functions
CommandQuery
Content
- Introduction
-
Packages
-
CommandQuery
⚙️ -
CommandQuery.AspNetCore
🌐 -
CommandQuery.AWSLambda
⚡ -
CommandQuery.AzureFunctions
⚡ -
CommandQuery.GoogleCloudFunctions
⚡ -
CommandQuery.Client
🧰 -
CommandQuery.AspNet.WebApi
🌐
-
- Upgrading
- Acknowledgements
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.
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
⚙️
Command Query Separation for .NET
- 📃 README: CommandQuery.md
- 💁 Samples:
-
CommandQuery.Sample.Contracts
-
CommandQuery.Sample.Handlers
-
CommandQuery.AspNetCore
🌐
Command Query Separation for ASP.NET Core
- 📃 README: CommandQuery.AspNetCore.md
- 💁 Samples:
-
CommandQuery.Sample.AspNetCore.V3
-
CommandQuery.Sample.AspNetCore.V3.Tests
-
CommandQuery.Sample.AspNetCore.V5
-
CommandQuery.Sample.AspNetCore.V5.Tests
-
CommandQuery.AWSLambda
⚡
Command Query Separation for AWS Lambda
- 📃 README: CommandQuery.AWSLambda.md
- 💁 Samples:
-
CommandQuery.Sample.AWSLambda
-
CommandQuery.Sample.AWSLambda.Tests
-
CommandQuery.AzureFunctions
⚡
Command Query Separation for Azure Functions
- 📃 README: CommandQuery.AzureFunctions.md
- 💁 Samples:
-
CommandQuery.Sample.AzureFunctions.V3
-
CommandQuery.Sample.AzureFunctions.V3.Tests
-
CommandQuery.Sample.AzureFunctions.V5
-
CommandQuery.Sample.AzureFunctions.V5.Tests
-
CommandQuery.GoogleCloudFunctions
⚡
Command Query Separation for Google Cloud Functions
- 📃 README: CommandQuery.GoogleCloudFunctions.md
- 💁 Samples:
-
CommandQuery.Sample.GoogleCloudFunctions
-
CommandQuery.Sample.GoogleCloudFunctions.Tests
-
CommandQuery.Client
🧰
Clients for CommandQuery APIs
- 📃 README: CommandQuery.Client.md
- 💁 Samples:
-
CommandQuery.Sample.Client
-
CommandQuery.AspNet.WebApi
🌐
Command Query Separation for ASP.NET Web API 2
⛔ This package is no longer maintained and new versions will not be published
- 📃 README: CommandQuery.AspNet.WebApi.md
- 💁 Samples:
-
CommandQuery.Sample.AspNet.WebApi
-
CommandQuery.Sample.AspNet.WebApi.Tests
-
Upgrading
⬆️ Upgrading from version
1.0.0
to2.0.0
Upgrade command/query handlers:
- Upgrade the project target framework from ~~
net461
~~ tonetstandard2.0
or greater - Add a
CancellationToken
parameter to theHandleAsync
methods in classes that implementICommandHandler<TCommand>
,ICommandHandler<TCommand, TResult>
andIQueryHandler<TQuery, TResult>
Upgrade AspNet.WebApi:
- Migrate from
CommandQuery.AspNet.WebApi
toCommandQuery.AspNetCore
Upgrade AspNetCore:
- Consider to upgrade the project target framework to
netcoreapp3.1
ornet5.0
- Consider to use the extension methods
AddCommandControllers
andAddQueryControllers
inStartup.cs
Upgrade AWSLambda:
- Upgrade the project target framework to
netcoreapp3.1
- Change the method invocation on
CommandFunction
andQueryFunction
from ~~Handle
~~ toHandleAsync
- Change the argument on
HandleAsync
methods from ~~ILambdaContext
~~ toILambdaLogger
- Consider to use the extension methods
AddCommandFunction
andAddQueryFunction
onIServiceCollection
- Consider to use the
JsonSerializerOptions
constructor argument inCommandFunction
andQueryFunction
to configure JSON serialization/deserialization
Upgrade AzureFunctions:
- Upgrade the project target framework to
netcoreapp3.1
ornet5.0
- Change the method invocation on
CommandFunction
andQueryFunction
from ~~Handle
~~ toHandleAsync
- Consider to use the extension methods
AddCommandControllers
andAddQueryControllers
inStartup.cs
/Program.cs
- Consider to use the
CancellationToken
argument onHandleAsync
methods innetcoreapp3.1
projects - Consider to use the
JsonSerializerSettings
/JsonSerializerOptions
constructor argument inCommandFunction
andQueryFunction
to configure JSON serialization/deserialization
Upgrade Client:
- Change the method invocation on
CommandClient
andQueryClient
from ~~Post
~~ toPostAsync
and from ~~Get
~~ toGetAsync
- Consider to use the
AddHttpClient
extension method onIServiceCollection
to create theCommandClient
andQueryClient
(see sample) - Consider to use the
CancellationToken
argument to methods inCommandClient
andQueryClient
Validation:
- Consider to use the
AssertConfigurationIsValid
method onCommandProcessor
andQueryProcessor
to validate handler and type configuration
Acknowledgements
Inspired by Steven van Deursen blog posts: