Just.Cqrs
1.1.0
.NET 8.0
This package targets .NET 8.0. The package is compatible with this framework or higher.
.NET Standard 2.1
This package targets .NET Standard 2.1. The package is compatible with this framework or higher.
dotnet add package Just.Cqrs --version 1.1.0
NuGet\Install-Package Just.Cqrs -Version 1.1.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="Just.Cqrs" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Just.Cqrs --version 1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Just.Cqrs, 1.1.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.
// Install Just.Cqrs as a Cake Addin #addin nuget:?package=Just.Cqrs&version=1.1.0 // Install Just.Cqrs as a Cake Tool #tool nuget:?package=Just.Cqrs&version=1.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Just.Cqrs
Inspired by MediatR
Just.Cqrs is a lightweight, easy-to-use C# library designed to simplify the implementation of the Command Query Responsibility Segregation (CQRS) pattern in .NET applications. With a focus on simplicity and flexibility, Just.Cqrs provides a clean and intuitive way to separate command and query logic.
Features
- Separate dispatching of Commands/Queries
- Middleware-like Behaviors
Compatibility
Just.Cqrs is built for .Net Standard 2.1 and .NET 8.0 and 9.0.
Getting Started
Install from NuGet.org
# install the package using NuGet
dotnet add package Just.Cqrs
Register in DI with IServiceCollection
services.AddCqrs(opt => opt
.AddQueryHandler<SomeQueryHandler>()
.AddCommandHandler<SomeCommandHandler>()
.AddBehavior<SomeQueryBehavior>()
.AddOpenBehavior(typeof(LoggingBehavior<,>))
);
Example Usage
Define a Query and Handler
record GetUserByIdQuery(int UserId) : IKnownQuery<User>;
class GetUserByIdQueryHandler : IQueryHandler<GetUserByIdQuery, User>
{
public ValueTask<User> Handle(GetUserByIdQuery query, CancellationToken cancellationToken)
{
// Fetch user logic here
}
}
// Use Dispatcher to execute the query
class GetUserByIdUseCase(IQueryDispatcher dispatcher)
{
public async Task<IResult> Execute(int userId, CancellationToken cancellationToken)
{
var user = await dispatcher.Dispatch(new GetUserByIdQuery(userId), cancellationToken);
}
}
* the same principles apply to commands
Define a Behavior
class LoggingBehavior<TRequest, TResult>(ILogger logger) : IDispatchBehavior<TRequest, TResult>
where TRequest: notnull
{
public async ValueTask<TResult> Handle(
TRequest request,
DispatchFurtherDelegate<TResult> next,
CancellationToken cancellationToken)
{
logger.LogInformation("Handling request: {RequestType}", typeof(TRequest).Name);
var result = await next();
logger.LogInformation("Request handled: {RequestType}", typeof(TRequest).Name);
return result;
}
}
class SomeQueryBehavior : IDispatchBehavior<SomeQuery, SomeQueryResult>
{
public async ValueTask<SomeQueryResult> Handle(
SomeQuery request,
DispatchFurtherDelegate<SomeQueryResult> next,
CancellationToken cancellationToken)
{
// do something
return await next();
}
}
License
Just.Cqrs is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. 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 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. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.1
- Just.Cqrs.Abstractions (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
-
net8.0
- Just.Cqrs.Abstractions (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
-
net9.0
- Just.Cqrs.Abstractions (>= 1.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.