YAMCqrs.Core 10.0.1

dotnet add package YAMCqrs.Core --version 10.0.1
                    
NuGet\Install-Package YAMCqrs.Core -Version 10.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="YAMCqrs.Core" Version="10.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="YAMCqrs.Core" Version="10.0.1" />
                    
Directory.Packages.props
<PackageReference Include="YAMCqrs.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add YAMCqrs.Core --version 10.0.1
                    
#r "nuget: YAMCqrs.Core, 10.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package YAMCqrs.Core@10.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=YAMCqrs.Core&version=10.0.1
                    
Install as a Cake Addin
#tool nuget:?package=YAMCqrs.Core&version=10.0.1
                    
Install as a Cake Tool

YAMCqrs.Core

Documentacion en espaΓ±ol

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:

  • ICommandInterceptor
  • IQueryInterceptor
  • CommandInterceptorBase
  • QueryInterceptorBase

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


πŸ“‹ Dependencies

This package has no external dependencies.

Only the .NET runtime is required.

Product 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last Updated
10.0.1 54 5/18/2026
10.0.0 70 5/17/2026