Just.Cqrs.Abstractions
1.0.0
See the version list below for details.
dotnet add package Just.Cqrs.Abstractions --version 1.0.0
NuGet\Install-Package Just.Cqrs.Abstractions -Version 1.0.0
<PackageReference Include="Just.Cqrs.Abstractions" Version="1.0.0" />
paket add Just.Cqrs.Abstractions --version 1.0.0
#r "nuget: Just.Cqrs.Abstractions, 1.0.0"
// Install Just.Cqrs.Abstractions as a Cake Addin #addin nuget:?package=Just.Cqrs.Abstractions&version=1.0.0 // Install Just.Cqrs.Abstractions as a Cake Tool #tool nuget:?package=Just.Cqrs.Abstractions&version=1.0.0
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 was computed. 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. |
.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. |
-
.NETStandard 2.1
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Just.Cqrs.Abstractions:
Package | Downloads |
---|---|
Just.Cqrs
Lightweight, easy-to-use C# library designed to simplify the implementation of the Command Query Responsibility Segregation (CQRS) pattern. |
GitHub repositories
This package is not used by any popular GitHub repositories.