CqrsTemplate 1.0.0

dotnet add package CqrsTemplate --version 1.0.0
                    
NuGet\Install-Package CqrsTemplate -Version 1.0.0
                    
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="CqrsTemplate" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CqrsTemplate" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="CqrsTemplate" />
                    
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 CqrsTemplate --version 1.0.0
                    
#r "nuget: CqrsTemplate, 1.0.0"
                    
#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 CqrsTemplate@1.0.0
                    
#: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=CqrsTemplate&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=CqrsTemplate&version=1.0.0
                    
Install as a Cake Tool

CQRS Template Library 📌 Introduction

CQRS Template Library is a minimalistic template for implementing the CQRS (Command Query Responsibility Segregation) pattern in .NET projects. It provides basic interfaces for commands and queries, along with their handlers, making it easier to structure code and separate logic into read and write operations. 📑 Table of Contents

Introduction

Installation

Usage

Interfaces

    ICommand

    ICommandHandler

    IQuery

Example

Dependencies

Features

License

💾 Installation

Add the library to your .NET project:

dotnet add package CQRS.Template

(package name is placeholder — replace with the actual NuGet package name when published) 🚀 Usage

Define a command implementing ICommand<TResponse>.

Create a command handler implementing ICommandHandler<TCommand, TResponse>.

Define a query implementing IQuery<TResponse>.

Create a query handler using IRequestHandler<TQuery, TResponse> (from MediatR).

📂 Interfaces ICommand

public interface ICommand : ICommand<Unit>;
public interface ICommand<out TResponse> : IRequest<TResponse>;

Represents a command that modifies the system state.
May return a result (TResponse) or Unit for void-like operations.
ICommandHandler

public interface ICommandHandler<in TCommand>
    : ICommandHandler<TCommand, Unit>
    where TCommand : ICommand<Unit>, IRequest<Unit>;

public interface ICommandHandler<in TCommand, TResponse>
    : IRequestHandler<TCommand, TResponse>
    where TCommand : ICommand<TResponse>, IRequest<TResponse>
    where TResponse : notnull;

Defines a handler for commands.
The implementation contains the business logic to execute the command.
IQuery

public interface IQuery<out TResponse> : IRequest<TResponse>
    where TResponse : notnull;

Represents a read-only request for retrieving data without modifying the system state. 📌 Example

// Command

public record CreateUserCommand(string Name) : ICommand<Guid>;

// Command Handler

public class CreateUserHandler : ICommandHandler<CreateUserCommand, Guid>
{
    public async Task<Guid> Handle(CreateUserCommand command, CancellationToken cancellationToken)
    {
        var id = Guid.NewGuid();
        // Save user logic
        return id;
    }
}

// Query

public record GetUserQuery(Guid Id) : IQuery<UserDto>;

// Query Handler

public class GetUserHandler : IRequestHandler<GetUserQuery, UserDto>
{
    public async Task<UserDto> Handle(GetUserQuery query, CancellationToken cancellationToken)
    {
        // Retrieve user logic
    }
}

📦 Dependencies

MediatR — used for dispatching commands and queries.

✨ Features

Clear separation of read and write operations.

Easy integration with MediatR.

Flexible and extensible design.

Strongly typed request/response contracts.

📜 License

BSD 3-Clause License — free to use, modify, and distribute with attribution. See the LICENSE file for details.

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.

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
1.0.0 127 8/14/2025