I was interested in learning more about Command Query Separation (CQS). I ended up with a NuGet package for ASP.NET Core microservice apps.

You can get the binaries and source at:


Command Query Separation (CQS) for ASP.NET Core Microservices

  • Build microservices that separate the responsibility of commands and queries.
  • Focus on implementing the handlers for commands and queries, not on writing Web APIs.
  • CommandQuery provides generic actions for handling the execution of all commands and queries.
  • CommandQuery provides an API based on HTTP POST, not a REST API

Command Query Separation in a nutshell:

  • Commands
    • Writes (Create, Update, Delete) data
  • Queries
    • Reads and returns data

Microservices could be done with ASP.NET Core



  1. Create a new ASP.NET Core project
  2. Install the CommandQuery package from NuGet
    • PM> Install-Package CommandQuery
  3. Create controllers
    • Inherit from BaseCommandController and BaseQueryController
  4. Create commands and command handlers
    • Implement ICommand and ICommandHandler<in TCommand>
  5. Create queries and query handlers
    • Implement IQuery<TResult> and IQueryHandler<in TQuery, TResult>
  6. Add the handlers to the dependency injection container
    • services.AddCommands(typeof(Startup).GetTypeInfo().Assembly);
    • services.AddQueries(typeof(Startup).GetTypeInfo().Assembly);

Sample code is available on GitHub: CommandQuery.Sample


I wanted to:

  • Publish my very first NuGet package
  • Try ASP.NET Core / .NET Core
  • Learn more about CQS


The great articles by Steven van Deursen:


I have not considered things like:

  • Service Discovery
  • Authentication / Authorization
  • Caching
  • etc.