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
<PackageReference Include="NPv.CQS.Abstractions" Version="1.0.1" />
<PackageVersion Include="NPv.CQS.Abstractions" Version="1.0.1" />
<PackageReference Include="NPv.CQS.Abstractions" />
paket add NPv.CQS.Abstractions --version 1.0.1
#r "nuget: NPv.CQS.Abstractions, 1.0.1"
#:package NPv.CQS.Abstractions@1.0.1
#addin nuget:?package=NPv.CQS.Abstractions&version=1.0.1
#tool nuget:?package=NPv.CQS.Abstractions&version=1.0.1
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 (seeNPv.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 | Versions 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. |
-
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.