YAMCqrs.Core
10.0.1
dotnet add package YAMCqrs.Core --version 10.0.1
NuGet\Install-Package YAMCqrs.Core -Version 10.0.1
<PackageReference Include="YAMCqrs.Core" Version="10.0.1" />
<PackageVersion Include="YAMCqrs.Core" Version="10.0.1" />
<PackageReference Include="YAMCqrs.Core" />
paket add YAMCqrs.Core --version 10.0.1
#r "nuget: YAMCqrs.Core, 10.0.1"
#:package YAMCqrs.Core@10.0.1
#addin nuget:?package=YAMCqrs.Core&version=10.0.1
#tool nuget:?package=YAMCqrs.Core&version=10.0.1
YAMCqrs.Core
Core library of the YAMCqrs ecosystem built around the principles of CQRS (Command Query Responsibility Segregation) and the Mediator pattern as the orchestration mechanism.
This package provides a lightweight, high-performance abstraction layer for implementing Commands, Queries, Handlers, Interceptors, and dispatching pipelines in .NET applications.
βοΈ Installation
dotnet add package YAMCqrs.Core
π Quick Start
Register YAMCqrs in the dependency injection container:
builder.Services.AddYAMCqrs();
Once registered, the framework automatically discovers and registers:
- Command Handlers
- Query Handlers
- Interceptors
- Dispatcher implementations
π Main Concepts
ICommand & IQuery
YAMCqrs separates read and write operations using independent abstractions:
ICommand<TResult>β Represents write operations or actions that modify state.IQuery<TResult>β Represents read-only operations.
This separation promotes:
- Cleaner architecture
- Explicit intent
- Better scalability
- Easier testing and maintenance
Example:
public sealed class CreateUserCommand : ICommand<Guid>
{
public string Name { get; set; } = string.Empty;
}
ICommandHandler & IQueryHandler
Handlers contain the business logic associated with a specific Command or Query.
Example:
internal sealed class CreateUserCommandHandler
: ICommandHandler<CreateUserCommand, Guid>
{
public async Task<Result<Guid>> HandleAsync(
CreateUserCommand command,
CancellationToken cancellationToken = default)
{
// Business logic here
return Result<Guid>.Ok(Guid.NewGuid());
}
}
Result Pattern
The framework uses a Result<T> object instead of Exceptions for expected business validation failures.
Benefits:
- Avoids using Exceptions for control flow
- Improves readability
- Makes failures explicit
- Better performance under validation-heavy scenarios
Example:
return Result<string>.Failure("User already exists");
Interceptors
Interceptors allow adding cross-cutting concerns to the execution pipeline.
Common use cases:
- Logging
- Auditing
- Metrics
- Validation
- Tracing
- Security checks
Available abstractions:
ICommandInterceptorIQueryInterceptorCommandInterceptorBaseQueryInterceptorBase
Interceptors require explicit Layer and Order definitions to ensure deterministic execution order.
Example:
internal sealed class LoggingInterceptor<TCommand, TResult>
: ICommandInterceptor<TCommand, TResult>
where TCommand : ICommand<TResult>
{
public Task OnBeforeAsync(
TCommand command,
CancellationToken cancellationToken)
{
Console.WriteLine($"Executing {typeof(TCommand).Name}");
return Task.CompletedTask;
}
}
IDispatcher
IDispatcher is the main entry point used to execute Commands and Queries.
Example:
var result = await dispatcher.SendAsync(command);
if (result.IsFailure)
{
return BadRequest(result.Error);
}
return Ok(result.Value);
β‘ Performance & Source Generation
YAMCqrs.Core uses Source Generators to automatically generate:
- Dependency Injection registrations
- Dispatcher implementations
- Handler mappings
This design avoids runtime Reflection and improves:
- Startup performance
- Execution performance
- AOT compatibility
- Native trimming support
π οΈ Implementation Details
Features Included
- CQRS abstractions
- Mediator orchestration
- Dispatcher pipeline
- Interceptor pipeline
- Result pattern
- Source-generated DI registration
- Reflection-free dispatcher generation
Architecture Goals
- High performance
- Low allocations
- Explicit pipelines
- Predictable execution
- Clean separation of concerns
- Minimal dependencies
π Recommended Reading
π Dependencies
This package has no external dependencies.
Only the .NET runtime is required.
| 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
NuGet packages (2)
Showing the top 2 NuGet packages that depend on YAMCqrs.Core:
| Package | Downloads |
|---|---|
|
YAMCqrs.EventBus.Core
Package Description |
|
|
YAMCqrs.EventBus.Provider.Kafka
Package Description |
GitHub repositories
This package is not used by any popular GitHub repositories.