NPv.CQS.Infrastructure
2.2.0
See the version list below for details.
dotnet add package NPv.CQS.Infrastructure --version 2.2.0
NuGet\Install-Package NPv.CQS.Infrastructure -Version 2.2.0
<PackageReference Include="NPv.CQS.Infrastructure" Version="2.2.0" />
<PackageVersion Include="NPv.CQS.Infrastructure" Version="2.2.0" />
<PackageReference Include="NPv.CQS.Infrastructure" />
paket add NPv.CQS.Infrastructure --version 2.2.0
#r "nuget: NPv.CQS.Infrastructure, 2.2.0"
#:package NPv.CQS.Infrastructure@2.2.0
#addin nuget:?package=NPv.CQS.Infrastructure&version=2.2.0
#tool nuget:?package=NPv.CQS.Infrastructure&version=2.2.0
NPv.CQS.Infrastructure
Infrastructure for declarative execution of commands and queries in CQS-based applications.
Includes default implementations, Unit of Work executor, and Autofac integration.
β¨ Overview
NPv.CQS.Infrastructure provides essential building blocks for executing commands and queries defined using NPv.CQS.Abstractions.
It includes:
ICommandBuilderandIQueryBuilderfor resolving and executing handlers,UnitOfWorkCommandExecutorfor transactional command execution,- Autofac module for automatic handler registration by namespace.
This package is intended for the application or composition root layers, where behaviors are wired and executed.
π¨ Breaking Changes in v2.0.0
Starting with v2.1.0, all commands now return a Result (from NPv.ResultPattern) instead of being void tasks.
Before (v1.x):
public class CreateOrderCommand : ICommand<CreateOrderCommandContext> { public Task ExecuteAsync(CreateOrderCommandContext context) { // Domain logic return Task.CompletedTask; } }After (v2.x):
public class CreateOrderCommand : ICommand<CreateOrderCommandContext> { public Task<Result> ExecuteAsync(CreateOrderCommandContext context) { if (context.Amount <= 0) return Task.FromResult(Result.Failure(new Error("Validation.Invalid", "Amount"))); // Domain logic return Task.FromResult(Result.Success()); } }
ICommandBuilder and ICommandExecutor have been updated to propagate the Result.
UnitOfWorkCommandExecutor now commits the Unit of Work only if the result was successful.
π§ Key Features
- π¦ Built-in
ICommandBuilderandIQueryBuilderimplementations - π‘ Centralized command and query execution via
ICommandBuilderandIQueryBuilder - π§©
CQSModulefor seamless Autofac integration via namespace scanning - πΌ
UnitOfWorkCommandExecutorfor wrapping commands in a Unit of Work with automatic commit on success - π‘ Compatible with all abstractions from
NPv.CQS.Abstractions
π¦ Installation
dotnet add package NPv.CQS.Infrastructure
π§ͺ Usage Example
1. Register Autofac Module (in Program.cs)
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
builder.Host.ConfigureContainer<ContainerBuilder>(container =>
{
container.RegisterModule(new CQSModule("YourApp.HandlersNamespace"));
});
2. Execute a Command Declaratively
var result = await _commandExecutor.ExecuteAsync(new CreateOrderCommandContext(orderId, amount));
if (result.IsFailure)
{
return BadRequest(result.Errors);
}
return Ok();
3. Execute a Query Declaratively
var order = await _queryBuilder.For<Order>().With(new FindById(orderId));
π§© Components Included
| Component | Purpose |
|---|---|
| CQSModule | Autofac module for scanning and registering command/query handlers |
| CommandBuilder | Resolves and executes ICommand<TContext> for a given context |
| QueryBuilder | Resolves and executes IQuery<TCriterion, TResult> for a given criterion |
| UnitOfWorkCommandExecutor | Executes commands inside a Unit of Work, committing only on success |
| Default implementations | Internal infrastructure for resolving types and linking abstractions |
π Related Packages
NPv.CQS.Abstractionsβ core interfaces and contracts (now v2.0.0 with Result support)NPv.ResultPatternβ lightweight Result pattern implementationNPv.Uow.Abstractionsβ unit of work contract for transactional execution
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
- Autofac.Extras.AggregateService (>= 6.1.2)
- NPv.CQS.Abstractions (>= 2.1.1)
- NPv.Uow.Abstractions (>= 1.1.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.2 | 132 | 3/7/2026 |
| 3.0.1 | 141 | 2/1/2026 |
| 3.0.0 | 214 | 12/24/2025 |
| 2.4.1 | 240 | 10/1/2025 |
| 2.4.0 | 224 | 10/1/2025 |
| 2.3.1 | 155 | 9/27/2025 |
| 2.3.0 | 160 | 9/27/2025 |
| 2.2.0 | 173 | 9/26/2025 |
| 2.1.1 | 248 | 9/22/2025 |
| 2.1.0 | 241 | 9/22/2025 |
| 2.0.0 | 244 | 9/21/2025 |
| 1.1.0 | 228 | 8/10/2025 |
| 1.0.2 | 198 | 5/23/2025 |
| 1.0.1 | 209 | 5/19/2025 |
| 1.0.0 | 219 | 5/19/2025 |