DotRMediator 1.0.0

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

DotRMediator

.NET License

DotRMediator is a .NET library that implements the Mediator pattern in-process, inspired by MediatR. It decouples senders from handlers, supports CQRS architectures, and enables pipeline composition for cross-cutting concerns such as validation, logging, and exception handling.


Table of contents


Why use it?

DotRMediator centralizes application communication through typed messages:

  • Commands/Queries (Request/Response): one handler per request
  • Notifications/Events: fan-out to multiple handlers
  • Pipeline Behaviors: middleware for cross-cutting concerns
  • Stream Requests: asynchronous responses via IAsyncEnumerable<T>
  • Exception Handling: handlers and actions for request failures

No heavy dependencies — only Microsoft.Extensions.DependencyInjection.


Installation

Add a project reference:

dotnet add package DotRMediator

Or reference the project directly:

dotnet add src/MyApp/MyApp.csproj reference src/DotRMediator/DotRMediator.csproj

Quick start

1. Define a request and its handler

public sealed record GetUserByIdQuery(int UserId) : IRequest<UserDto>;

public sealed class GetUserByIdHandler : IRequestHandler<GetUserByIdQuery, UserDto>
{
    public Task<UserDto> Handle(GetUserByIdQuery request, CancellationToken cancellationToken)
    {
        var user = new UserDto(request.UserId, "Jane Doe");
        return Task.FromResult(user);
    }
}

public sealed record UserDto(int Id, string Name);

2. Register with the DI container

builder.Services.AddDotRMediator(cfg =>
{
    cfg.RegisterServicesFromAssembly(typeof(Program).Assembly);
    cfg.AddOpenBehavior(typeof(LoggingBehavior<,>));
});

3. Send the request via IMediator

public class UsersController : ControllerBase
{
    private readonly IMediator _mediator;

    public UsersController(IMediator mediator) => _mediator = mediator;

    [HttpGet("{id:int}")]
    public async Task<UserDto> Get(int id, CancellationToken cancellationToken)
    {
        return await _mediator.Send(new GetUserByIdQuery(id), cancellationToken);
    }
}

Features

Feature Main interface Description
Request with response IRequest<TResponse> Sends a request and awaits a response
Request without response IRequest Returns Unit
Notifications INotification Publishes an event to N handlers
Pipeline IPipelineBehavior<,> Middleware around handlers
Streams IStreamRequest<T> Streaming responses
Pre/Post processing IRequestPreProcessor<>, IRequestPostProcessor<,> Hooks before/after the handler
Exceptions IRequestExceptionHandler<,,>, IRequestExceptionAction<,> Handling and side effects on failures

See the full documentation for advanced examples.


Documentation

Document Content
docs/README.md Documentation index
docs/getting-started.md Step-by-step guide
docs/requests-and-notifications.md Requests, commands, queries, and events
docs/behaviors.md Pipeline behaviors and execution order
docs/streams-and-exceptions.md Streams and exception handling

Running tests

dotnet test

The suite includes 14 unit tests covering request dispatch, notification publishing, pipeline behaviors, pre/post-processors, streams, and exception handling.


Comparison with MediatR

DotRMediator implements the core MediatR feature set:

MediatR DotRMediator
IRequest<T> / IRequest
IRequestHandler<,> / IRequestHandler<>
INotification / INotificationHandler<>
IMediator / ISender / IPublisher
IPipelineBehavior<,>
IStreamRequest<T> / IStreamRequestHandler<,>
IRequestPreProcessor<> / IRequestPostProcessor<,>
IRequestExceptionHandler<,,> / IRequestExceptionAction<,>
AddMediatR / assembly scan AddDotRMediator
Unit

License

This project is licensed under the terms of the LICENSE file.

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.0 118 7/17/2026