SimpleMediatR 1.0.0

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

SimpleMediatR

A lightweight and easy-to-use implementation of the MediatR pattern for .NET Core applications. This library provides a clean and decoupled way to send request, and publish notifications within your application.

If you are looking for a simple and effective way to manage communication between components in your .NET Core application, SimpleMediatR is the perfect solution.

✨ Features

  • Supports request/response and notification patterns
  • Decouples business logic using the mediator design pattern
  • Lightweight and minimal dependencies
  • Easy to integrate into existing .NET Core projects

📦 Installation

dotnet add package SimpleMediatR

Or via NuGet Package Manager:

Install-Package SimpleMediatR

🛠️ Usage

  1. Register MediatR in your DI Container
builder.Services.AddMediatR(); // Automatically registers all handlers in the assembly
  1. Define a Request and its Handler
class Ping : IRequest<string>
{
    public string Message { get; set; } = string.Empty;
}

class PingHandler : IRequestHandler<Ping, string>
{
    public Task<string> HandleAsync(Ping request, CancellationToken cancellationToken)
    {
        return Task.FromResult($"Pong: {request.Message}");
    }
}


var ping = new Ping { Message = "Hello, World!" };

// Inject `IMediatR  mediatR` then use it
var result = await mediatR.SendAsync(ping);

logger.LogInformation($"Received response  ({result})");

🔔 Notifications

You can also publish notifications to multiple handlers:


class NewUserCreatedEvent : INotification
{
    public string FirstName { get; set; } = string.Empty;
    public string LastName { get; set; } = string.Empty;
    public Guid Id { get; set; }
}

class NewUserNotificationHandler(ILogger<NewUserNotificationHandler> logger) : INotificationHandler<NewUserCreatedEvent>
{
    public async Task HandleAsync(NewUserCreatedEvent newUser, CancellationToken cancellationToken)
    {
        logger.LogInformation($"Received notification: FirstName: {newUser.FirstName} LastName: {newUser.LastName} UserId: {newUser.Id}");
        await Task.CompletedTask;
    }
}

// Publishing when a new user is created
 await mediatR.PublishAsync(new NewUserCreatedEvent
        {
            FirstName = request.User.FirstName,
            LastName = request.User.LastName,
            Id = request.User.Id
        }, cancellationToken);

More examples:

Checkout the examples folder for more usage examples.

🤝 Contributing

Contributions are welcome! Feel free to open issues, suggest features, or submit pull requests.

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
1.0.0 1,659 4/9/2025