cqrs-mediatr
1.0.2
dotnet add package cqrs-mediatr --version 1.0.2
NuGet\Install-Package cqrs-mediatr -Version 1.0.2
<PackageReference Include="cqrs-mediatr" Version="1.0.2" />
<PackageVersion Include="cqrs-mediatr" Version="1.0.2" />
<PackageReference Include="cqrs-mediatr" />
paket add cqrs-mediatr --version 1.0.2
#r "nuget: cqrs-mediatr, 1.0.2"
#addin nuget:?package=cqrs-mediatr&version=1.0.2
#tool nuget:?package=cqrs-mediatr&version=1.0.2
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
, andICQRSMediatr
. - 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
- From NuGet package repository:
dotnet add package cqrs-mediatr
From sources:
Clone the repository:
git clone <repository-url> cd CQRSMediatr
Build the project:
dotnet build
Run tests (if applicable):
dotnet test
Usage
- Define your commands and queries by implementing
ICommand
andIQuery
interfaces. - Create handlers for your commands and queries by implementing
ICommandHandler
andIQueryHandler
interfaces. - 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 | Versions 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. |
-
net8.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Added CancellationToken to handlers call.