Dom.Mediator 1.0.1

dotnet add package Dom.Mediator --version 1.0.1
                    
NuGet\Install-Package Dom.Mediator -Version 1.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="Dom.Mediator" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dom.Mediator" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Dom.Mediator" />
                    
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 Dom.Mediator --version 1.0.1
                    
#r "nuget: Dom.Mediator, 1.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 Dom.Mediator@1.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=Dom.Mediator&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Dom.Mediator&version=1.0.1
                    
Install as a Cake Tool

NuGet License: MIT

Dom.Mediator

Dom.Mediator is a clean, minimal implementation of the Mediator pattern for .NET, focused on:

  • ✅ Request/Response messaging (CQRS)
  • ✅ Composable pipeline behaviors (validation, logging, etc.)
  • ✅ Built-in Result Pattern handling with typed errors
  • ✅ Lightweight with minimal dependencies
  • ✅ Perfect fit for Minimal APIs or Clean Architecture

📦 Install via NuGet

dotnet add package Dom.Mediator

🚀 Quick Example

Commands (Actions without return values)

Define your command:

public record CreateTaskCommand(string Title, string? Description) : ICommand;

Create a handler:

public class CreateTaskHandler : ICommandHandler<CreateTaskCommand>
{
    public Task<Result> Handle(CreateTaskCommand command, CancellationToken cancellationToken)
    {
        // Perform action logic here
        return Task.FromResult(Result.Success());
    }
}

Queries (Read operations with return values)

Define your query:

public record GetTasksQuery() : IQuery<List<TaskItem>>;

Create a handler:

public class GetTasksHandler : IQueryHandler<GetTasksQuery, List<TaskItem>>
{
    public Task<Result<List<TaskItem>>> Handle(GetTasksQuery query, CancellationToken cancellationToken)
    {
        var tasks = GetTasksFromStore(); // Your logic here
        return Task.FromResult(Result<List<TaskItem>>.Success(tasks));
    }
}

Setup with Dependency Injection

builder.Services.AddMediator(config =>
{
    config.RegisterHandlers(typeof(Program).Assembly);
    
    // Add pipeline behaviors
    config.AddRequestResponseBehaviour(typeof(LoggingBehaviour<,>));
    config.AddCommandBehaviour(typeof(ValidationBehaviour<>));
});

📚 Samples & Examples

Check out the samples directory for complete working examples:

🧪 Testing: See the tests directory for unit tests, coverage reports, and testing documentation.

🌐 Minimal API Sample

A complete ASP.NET Core Minimal API implementation demonstrating:

  • Task Management API with CQRS pattern
  • Command & Query handlers with validation
  • Pipeline behaviors for logging and cross-cutting concerns
  • Result pattern integration with HTTP responses
  • Swagger documentation and endpoint configuration
cd samples/Dom.Mediator.Samples.MinimalApi
dotnet run

⚙️ Built-in Features

  • 🧱 Pipeline Behaviors: Add logging, validation, error handling in a clean chain
  • 🎯 Result Pattern: Native success/failure with structured error codes (Result<T> and Result)
  • 🔄 Auto-Handler Discovery: Reflective scanning via assembly registration
  • 💡 CQRS Support: Separate Command and Query handling with distinct interfaces
  • 🏗️ Dependency Injection: Built-in support for Microsoft DI container

🧩 Pipeline Behaviors

Add behaviors to intercept and process requests:

// For queries (request/response)
config.AddRequestResponseBehaviour(typeof(LoggingBehaviour<,>));

// For commands
config.AddCommandBehaviour(typeof(ValidationBehaviour<>));

Request/Response Behavior Interface:

public interface IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    Task<Result<TResponse>> Handle(
        TRequest request, 
        CancellationToken cancellationToken, 
        RequestHandlerDelegate<TResponse> next);
}

Command Behavior Interface:

public interface IPipelineBehavior<TCommand>
    where TCommand : ICommand
{
    Task<Result> Handle(
        TCommand command, 
        CancellationToken cancellationToken, 
        CommandHandlerDelegate next);
}

📜 License

Dom.Mediator is MIT licensed.

👤 Author

Made with ❤️ by André Dominic Santacroce

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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 was computed.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 116 8/6/2025
1.0.0 130 7/10/2025
1.0.0-preview.10 118 8/6/2025
1.0.0-preview.9 31 8/1/2025
1.0.0-preview.8 106 7/16/2025
1.0.0-preview.7 112 7/16/2025
1.0.0-preview.6 108 7/16/2025
1.0.0-preview.5 114 7/14/2025
1.0.0-preview.4 61 7/11/2025
1.0.0-preview.3 62 7/11/2025
1.0.0-preview.2 68 7/11/2025
1.0.0-preview.1 113 7/10/2025