NPv.CQS.Abstractions 1.0.1

dotnet add package NPv.CQS.Abstractions --version 1.0.1
                    
NuGet\Install-Package NPv.CQS.Abstractions -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NPv.CQS.Abstractions" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NPv.CQS.Abstractions" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="NPv.CQS.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NPv.CQS.Abstractions --version 1.0.1
                    
#r "nuget: NPv.CQS.Abstractions, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NPv.CQS.Abstractions@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NPv.CQS.Abstractions&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=NPv.CQS.Abstractions&version=1.0.1
                    
Install as a Cake Tool

NPv.CQS.Abstractions

Minimal, dependency-free contracts for applications following the Command-Query Separation (CQS) pattern.


✨ Overview

NPv.CQS.Abstractions is a foundational library containing interfaces and contracts for building systems based on the Command‑Query Separation (CQS) principle.

It does not include any infrastructure or implementation — only the minimal building blocks that let infrastructure resolve and invoke handlers automatically.

Use this package in your domain, application, or core layers to define behaviors without pulling in any dependencies.


🔧 Interfaces Included

🟢 Commands

Interface Purpose
ICommand<TContext> Represents an action that changes system state
ICommandContext Marker type for command input/context
ICommandBuilder Resolves and executes a command for a given context (container-agnostic contract)
ICommandExecutor Higher-level orchestrator for executing commands (e.g., can be wrapped with Unit of Work in infrastructure)

🔵 Queries

Interface Purpose
IQuery<TCriterion, TResult> Read-only operation returning data for a specific criterion
ICriterion Input object used to filter or parameterize queries
IQueryBuilder Fluent entrypoint: ForAsync<TResult>() ... With<TCriterion>(criterion)
IQueryFor<TResult> Continuation interface returned by IQueryBuilder for a specific TResult

📦 Installation

dotnet add package NPv.CQS.Abstractions

💡 Examples

Define a command

public record CreateOrderCommandContext(Guid OrderId, decimal Amount) : ICommandContext;

public class CreateOrderCommand : ICommand<CreateOrderCommandContext>
{
    public Task ExecuteAsync(CreateOrderCommandContext context)
    {
        // Domain logic here
        return Task.CompletedTask;
    }
}

Define a query

public record FindById(Guid Id) : ICriterion;

public class FindOrderByIdQuery(IOrderService orders) : IQuery<FindById, Order>
{
    public Task<Order> AskAsync(FindById criterion) =>
        orders.GetAsync(criterion.Id);
}

Use in application code

public class OrdersController(ICommandExecutor exec, IQueryBuilder queries)
{
    public Task Create(Guid id, decimal amount) =>
        exec.ExecuteAsync(new CreateOrderCommandContext(id, amount));

    public Task<Order> Get(Guid id) =>
        queries.ForAsync<Order>().With(new FindById(id));
}

Note: ICommandExecutor is just a contract; infrastructure can provide an implementation that wraps execution in a Unit of Work (see NPv.Uow.Abstractions) or adds logging/telemetry/retries.


📚 Designed For Use With

  • NPv.CQS.Infrastructure – runtime execution (dispatch via DI, Autofac/MS.DI modules)
  • NPv.Uow.Abstractions – optional Unit of Work contract for transactional execution
  • Any DI container or runtime

Author's Note

This library grew out of my long-standing personal interest in structuring and publishing open source packages. Over time, I’ve revisited and refined earlier internal utilities and ideas, giving them a more consistent shape and preparing them for wider reuse. Along the way, I’ve also taken the opportunity to explore how open source distribution and licensing work in the .NET ecosystem.

It’s a small step toward something I’ve always wanted to try — sharing practical, minimal tools that reflect years of learning, experimentation, and refinement.

Hopefully, someone finds it useful.

Nikolai 😛


⚖️ License

MIT — you are free to use this in commercial and open-source software.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on NPv.CQS.Abstractions:

Package Downloads
NPv.CQS.Infrastructure

Provides command and query execution infrastructure for CQS-based applications, with builder implementations and Autofac support.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 144 8/10/2025
1.0.0 171 5/19/2025