Simple .NET MediatR base Query, Command, CommandEvent and CommandEventQueueProcess behavior. RequestFilter, ResultFilter and Filter behaviours. Event Queue and Validation behaviors. Written on C#.
$ dotnet add package Cross.CQRSSimple .NET MediatR base Query, Command, Event, Validation and Filter.
Event Queue, Validation and Filter behaviors written on C#.
Main Features:
Queries, and QueryHandlers.
Implemented base patterns to work with Queries. The Queries used just to get any data.
Commands and CommandHandlers.
Implemented base patterns to work with Commands. The Commands used to modify entities.
CommandEvents, CommandEventHandlers, CommandEventWriter, CommandEventReader and CommandEventQueueProcessBehavior.
Implemented base patterns to create CommandEvents, approach how to write a new CommandEvents from the Commands, consuming patterns and behavior to handle it.
The main idea is to do some actions after the Commands have to be finished, to avoid cases when one Command call another one.
Added possibility to exclude the processing of some CommandEvents from Command transaction (even on throw Exception).
Filters.
Here included filter behavior based on RequestFilter and ResultFilter.
The RequestFilter allow to filter Queries and Commands requests before their execution.
The ResultFilter allow to filter Queries and Commands results after their execution.
Validation.
Here included validation behavior based on FluentValidation, that allow to validate Queries and Command before their execution.
.NET frameworks and Source Linking.
The repository contains .NET Standard 2.0, .NET 6, .NET 7 and .NET 8 projects.
Source linking enabled and symbol package is published to nuget symbols server, making debugging easier.
https://www.nuget.org/packages/Cross.CQRS
You should install Cross.CQRS with NuGet package:
Install-Package Cross.CQRS
Or via the .NET Core command line interface:
dotnet add package Cross.CQRS
Either commands, from Package Manager Console or .NET Core CLI, will download and install Cross.CQRS and all required dependencies.
IServiceCollectionCross.CQRS supports Microsoft.Extensions.DependencyInjection.Abstractions directly. To register Cross.CQRS services and handlers, use the configuration overload:
services.AddCQRS(cfg =>
{
cfg.RegisterFromAssemblies(typeof(Startup).Assembly);
});
or with RegisterFromAssemblyContaining:
services.AddCQRS(cfg =>
{
cfg.RegisterFromAssemblyContaining<Startup>();
});
Multiple assemblies:
services.AddCQRS(cfg =>
{
cfg.RegisterFromAssemblies(typeof(Startup).Assembly, typeof(Other).Assembly);
});
With license key:
services.AddCQRS(cfg =>
{
cfg.RegisterFromAssemblyContaining<Startup>();
cfg.LicenseKey = "<license key here>";
});
This registers (via MediatR with Scoped lifetime):
IMediator, ISender, IPublisher — scopedIRequestHandler<,> and IRequestHandler<> implementations — scopedINotificationHandler<> implementations — scopedIStreamRequestHandler<> implementations — scopedIRequestExceptionHandler<,,> and IRequestExceptionAction<,> implementations — scopedAdditionally registered:
IResultFilter<,> and IRequestFilter<> — scopedIHandlerLocator — singletonICommandEventQueue and its reader/writer — scopedLicenseCheckBehavior (mandatory license check on first CQRS request), CommandEventQueueProcessBehavior, RequestFilterBehavior, ValidationBehavior, ResultFilterBehavior — scopedThe license check runs automatically on the first CQRS request — no additional code required.
The method returns CqrsRegistrationSyntax for fluent configuration (e.g. adding custom behaviors).
License keys are available at peshkov.biz.
Contribution is welcomed. If you would like to provide a PR please add some testing.
Please use Wiki for documentation and usage examples.
Note - test project is not a part of nuget package. You have to clone repository.