LiteCqrs.Net
1.0.1
dotnet add package LiteCqrs.Net --version 1.0.1
NuGet\Install-Package LiteCqrs.Net -Version 1.0.1
<PackageReference Include="LiteCqrs.Net" Version="1.0.1" />
<PackageVersion Include="LiteCqrs.Net" Version="1.0.1" />
<PackageReference Include="LiteCqrs.Net" />
paket add LiteCqrs.Net --version 1.0.1
#r "nuget: LiteCqrs.Net, 1.0.1"
#:package LiteCqrs.Net@1.0.1
#addin nuget:?package=LiteCqrs.Net&version=1.0.1
#tool nuget:?package=LiteCqrs.Net&version=1.0.1
LiteCqrs.Net
A lightweight, dynamic-free, CQRS-flavored in-process mediator for .NET — an alternative to
MediatR that keeps an explicit Command/Query split instead of a unified IRequest.
Multi-targets netstandard2.0 (max reach: .NET Framework 4.6.1+, Mono, Unity) and net10.0
(in-box BCL, no polyfills).
What it does
ICommand<TResponse>/IQuery<TResponse>— commands change state, queries read; each has exactly one handler (ICommandHandler<,>/IQueryHandler<,>), dispatched viaISender.Send(...).- Dynamic-free dispatch: per-request-type wrapper classes cached in a process-lifetime
ConcurrentDictionary, built once via reflection and never touched again — nodynamic, no per-call reflection after the first dispatch of a given request type. - Ordered pipeline behaviors (
IPipelineBehavior<,>) — logging, validation, transactions, authorization, whatever you need. First-registered is outermost. Generic constraints on your behavior (e.g.where TRequest : ICommand<TResponse>) opt it in only for the requests that satisfy them. - Notifications / pub-sub (
INotification/INotificationHandler<>/IPublisher.Publish) — zero-or-more handlers per notification, run sequentially (safe with scoped, non-thread-safe dependencies like an EF CoreDbContext), failures isolated and aggregated rather than fail-fast — pluggable viaINotificationPublisherif you need a different strategy. - Exception behaviors (
IRequestExceptionHandler<,,>/IRequestExceptionAction<,>) — resolve by exception-type hierarchy (most-derived first), let a handler recover an exception into a response, or run an action that always fires regardless of recovery. - Streaming requests (
IStreamRequest<>/IStreamRequestHandler<,>/ISender.CreateStream) — lazyIAsyncEnumerable<T>responses with their own composableIStreamPipelineBehavior<,>. - Flexible registration —
AddLiteCqrs(cfg => { cfg.RegisterServicesFromAssembly(...); ... })scans one or more assemblies, catches duplicate handler registrations for commands/queries eagerly (a footgun MS DI otherwise resolves silently as "last one wins"), and lets you configure the service lifetime (defaults toScoped, not MediatR'sTransient).
Install
dotnet add package LiteCqrs.Net
Register
using LiteCqrs.Behaviors;
using LiteCqrs.DependencyInjection;
builder.Services.AddLiteCqrs(cqrs =>
{
cqrs.RegisterServicesFromAssemblyContaining<Program>();
cqrs.Lifetime = ServiceLifetime.Scoped; // default; set explicitly for clarity if you like
// First added = outermost.
cqrs.AddOpenBehavior(typeof(LoggingBehavior<,>)); // ready-made, ships in LiteCqrs.Behaviors
cqrs.AddOpenBehavior(typeof(MyValidationBehavior<,>));
cqrs.AddOpenBehavior(typeof(MyUnitOfWorkBehavior<,>));
});
Then inject ISender:
public sealed class CreateOrderEndpoint(ISender sender)
{
public Task<Result<OrderDto>> Post(CreateOrderCommand command, CancellationToken ct) =>
sender.Send(command, ct);
}
Why not just MediatR?
MediatR is unified around IRequest<TResponse>; LiteCqrs.Net keeps commands and queries as
distinct types on purpose — if your codebase already thinks in CQRS terms, the type system should
say so. Beyond that, the two libraries solve the same problem in a similar shape (pipeline
behaviors, notifications, streaming); pick whichever fits your project's conventions.
| 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. net10.0 is compatible. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. 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.0
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
-
net10.0
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.