SolTechnology.Core.CQRS
0.5.0
dotnet add package SolTechnology.Core.CQRS --version 0.5.0
NuGet\Install-Package SolTechnology.Core.CQRS -Version 0.5.0
<PackageReference Include="SolTechnology.Core.CQRS" Version="0.5.0" />
<PackageVersion Include="SolTechnology.Core.CQRS" Version="0.5.0" />
<PackageReference Include="SolTechnology.Core.CQRS" />
paket add SolTechnology.Core.CQRS --version 0.5.0
#r "nuget: SolTechnology.Core.CQRS, 0.5.0"
#:package SolTechnology.Core.CQRS@0.5.0
#addin nuget:?package=SolTechnology.Core.CQRS&version=0.5.0
#tool nuget:?package=SolTechnology.Core.CQRS&version=0.5.0
Overview
The SolTechnology.Core.CQRS library provides a complete CQRS (Command Query Responsibility Segregation) implementation built on MediatR. It includes the Result pattern for explicit success/failure handling, Chain handlers for complex multi-step operations, and automatic validation and logging through pipeline behaviors.
Registration
For installing the library, reference SolTechnology.Core.CQRS nuget package and invoke the appropriate registration methods:
// Register command handlers
services.RegisterCommands();
// Register query handlers
services.RegisterQueries();
// Register chain steps (for complex operations)
services.RegisterChain();
Configuration
No configuration is needed. The registration methods automatically:
- Register all command and query handlers from the calling assembly
- Configure FluentValidation for input validation
- Add logging and validation pipeline behaviors
Usage
- Define a Query and Handler
public class GetUserQuery : IRequest<Result<User>>
{
public int UserId { get; set; }
}
public class GetUserQueryHandler : IQueryHandler<GetUserQuery, User>
{
public async Task<Result<User>> Handle(GetUserQuery request, CancellationToken cancellationToken)
{
var user = await _userRepository.GetById(request.UserId);
if (user == null)
return Result<User>.Fail("User not found");
return Result<User>.Success(user);
}
}
- Define a Command and Handler
public class CreateUserCommand : IRequest<Result>
{
public string Name { get; set; }
public string Email { get; set; }
}
public class CreateUserCommandHandler : ICommandHandler<CreateUserCommand>
{
public async Task<Result> Handle(CreateUserCommand request, CancellationToken cancellationToken)
{
await _userRepository.Create(new User
{
Name = request.Name,
Email = request.Email
});
return Result.Success();
}
}
- Add Validation (Optional)
public class CreateUserCommandValidator : AbstractValidator<CreateUserCommand>
{
public CreateUserCommandValidator()
{
RuleFor(x => x.Name).NotEmpty().MaximumLength(100);
RuleFor(x => x.Email).NotEmpty().EmailAddress();
}
}
- Use Chain Pattern for Complex Operations
public class ComplexOperationContext : ChainContext<MyInput, MyOutput>
{
public string IntermediateData { get; set; }
}
public class Step1 : IChainStep<ComplexOperationContext>
{
public async Task<Result> Execute(ComplexOperationContext context)
{
// Step 1 logic
context.IntermediateData = "processed";
return Result.Success();
}
}
public class ComplexOperationHandler : ChainHandler<MyInput, ComplexOperationContext, MyOutput>
{
protected override async Task HandleChain()
{
await Invoke<Step1>();
await Invoke<Step2>();
await Invoke<Step3>();
}
}
- Result Pattern Usage
var result = await _mediator.Send(new GetUserQuery { UserId = 1 });
if (result.IsSuccess)
{
var user = result.Value;
// Use the user
}
else
{
var error = result.Error;
// Handle the error
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- FluentValidation (>= 11.11.0)
- FluentValidation.DependencyInjectionExtensions (>= 11.11.0)
- MediatR (>= 12.3.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.3)
- Microsoft.Extensions.Options (>= 10.0.0)
- SolTechnology.Core.Logging (>= 0.5.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on SolTechnology.Core.CQRS:
| Package | Downloads |
|---|---|
|
SolTechnology.Core.Api
ASP.NET Core API utilities including header-based API versioning, exception handling middleware, response envelope filters, and integration testing fixtures. Perfect foundation for building clean, testable APIs with consistent error handling and response formatting. |
|
|
SolTechnology.Core.Flow
Package Description |
|
|
SolTechnology.Core.Story
Story Framework - Unified workflow orchestration for multi-step business processes. Supports both simple automated chains and pausable workflows with persistence. Features Tale Code philosophy with StoryHandler, Chapters, and Context for readable, maintainable business logic. |
GitHub repositories
This package is not used by any popular GitHub repositories.