MDiator 0.0.13

There is a newer version of this package available.
See the version list below for details.
dotnet add package MDiator --version 0.0.13
                    
NuGet\Install-Package MDiator -Version 0.0.13
                    
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="MDiator" Version="0.0.13" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MDiator" Version="0.0.13" />
                    
Directory.Packages.props
<PackageReference Include="MDiator" />
                    
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 MDiator --version 0.0.13
                    
#r "nuget: MDiator, 0.0.13"
                    
#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 MDiator@0.0.13
                    
#: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=MDiator&version=0.0.13
                    
Install as a Cake Addin
#tool nuget:?package=MDiator&version=0.0.13
                    
Install as a Cake Tool

MDiator ๐Ÿงฉ

MDiator is a lightweight, extensible in-process messaging library for .NET.
It provides clean abstractions for sending requests and publishing events using a mediator pattern โ€” without the bloat.

Inspired by MediatR, built for performance and clarity.


๐Ÿš€ Features

  • Send<TRequest>: Handle a single request with a typed response
  • Publish<TEvent>: Broadcast events to multiple handlers
  • Auto-registration of handlers via assembly scanning
  • No reflection at runtime โ€“ uses compiled delegates
  • Minimal dependencies

๐Ÿ“ฆ Installation

Add it to your project (once published to NuGet):

dotnet add package MDiator

Register in Program.cs

services.AddMDiator(typeof(Program).Assembly);

๐Ÿงช Example Usage Define a Command

public class CreateUserCommand : IMDiatorRequest<string>
{
    public string UserName { get; set; }
}

public class CreateUserHandler : IMDiatorHandler<CreateUserCommand, string>
{
    public Task<string> Handle(CreateUserCommand command)
        => Task.FromResult($"Created user: {command.UserName}");
}
var result = await mediator.Send(new CreateUserCommand { UserName = "Mostafa" });

๐Ÿ“ฃ Event Example

public class OrderCreatedEvent : IMDiatorEvent
{
    public int OrderId { get; set; }
}

public class NotifyTeamHandler : IMDiatorEventHandler<OrderCreatedEvent>
{
    public Task Handle(OrderCreatedEvent e)
    {
        Console.WriteLine($"Notify team about order {e.OrderId}");
        return Task.CompletedTask;
    }
}
await mediator.Publish(new OrderCreatedEvent { OrderId = 123 });
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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
0.1.1 128 4/26/2025
0.0.13 127 4/18/2025
0.0.12 140 4/18/2025