cqrs-mediatr 1.0.2

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

NuGet Version NuGet Downloads

CQRSMediatr

CQRSMediatr is a .NET library that implements the Command Query Responsibility Segregation (CQRS) pattern using the Mediator design pattern. It provides interfaces and base implementations to simplify the development of CQRS-based applications.

Features

  • Command and Query Separation: Clearly separates commands (write operations) from queries (read operations).
  • Handler Abstraction: Provides interfaces for command and query handlers.
  • Extensibility: Easily extendable to fit your application's needs.

Project Structure

  • Interfaces/: Contains core interfaces such as ICommand, ICommandHandler, IQuery, IQueryHandler, and ICQRSMediatr.
  • RegisterCqrsMediatr.cs: Handles the registration of CQRS and Mediator components.
  • CqrsMediatr.cs: Main implementation file for the library.

Getting Started

Prerequisites

  • .NET 8.0 SDK or later

Installation

  1. From NuGet package repository:
    dotnet add package cqrs-mediatr
    

From sources:

  1. Clone the repository:

    git clone <repository-url>
    cd CQRSMediatr
    
  2. Build the project:

    dotnet build
    
  3. Run tests (if applicable):

    dotnet test
    

Usage

  1. Define your commands and queries by implementing ICommand and IQuery interfaces.
  2. Create handlers for your commands and queries by implementing ICommandHandler and IQueryHandler interfaces.
  3. Register the handlers and mediator in your application's dependency injection container using RegisterCqrsMediatr.cs.

Example:

public class CreateOrderCommand : ICommand {
    public string OrderId { get; set; }
    public string ProductName { get; set; }
}

public class CreateOrderCommandHandler : ICommandHandler<CreateOrderCommand> {
    public Task Handle(CreateOrderCommand command) {
        // Handle the command logic here
        return Task.CompletedTask;
    }
}

Registering in Dependency Injection (DI) Container

To register the CQRS Mediator in your application's DI container, use the following code in your Startup class or equivalent:

services.AddCqrsMediatr(typeof(Startup));

This will scan and register all command and query handlers in the assembly containing the specified type (Startup in this case).

Contributing

Contributions are welcome! Please fork the repository and submit a pull request.

License

MIT License

Copyright (c) 2025 Serhiy Krasovskyy xhunter74@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  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.2 433 5/7/2025
1.0.1 222 4/29/2025
1.0.0 260 4/27/2025

Added CancellationToken to handlers call.