SimpleMediatorLib 1.0.2

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

SimpleMediator

A simple, lightweight mediator pattern implementation for .NET with support for request/response handlers, notifications, and pipeline behaviors.

Installation

dotnet add package SimpleMediatorLib

Supported Frameworks

SimpleMediator supports a wide range of .NET implementations, including all future versions:

  • .NET Standard 2.0 - Compatible with .NET Framework 4.6.1+, .NET Core 2.0+
  • .NET Standard 2.1 - Compatible with .NET Core 2.1+, .NET 5+, .NET 6+, .NET 7+, .NET 8+, and all future .NET versions

By targeting .NET Standard, SimpleMediator automatically works with all current and future .NET implementations without requiring package updates.

Quick Start

1. Register SimpleMediator

using SimpleMediator;
using System.Reflection;

builder.Services.AddSimpleMediator(
    typeof(YourApplicationAssemblyMarker).Assembly
);

2. Create a Request

public sealed record GetUserQuery(int UserId)
    : IRequest<User>;

public sealed class GetUserQueryHandler
    : IRequestHandler<GetUserQuery, User>
{
    public Task<User> Handle(
        GetUserQuery request,
        CancellationToken cancellationToken)
    {
        // Your logic here
        return Task.FromResult(new User { Id = request.UserId });
    }
}

3. Send a Request

public class UserController : ControllerBase
{
    private readonly IMediator _mediator;

    public UserController(IMediator mediator)
    {
        _mediator = mediator;
    }

    [HttpGet("{id}")]
    public async Task<ActionResult<User>> GetUser(int id)
    {
        var user = await _mediator.Send(new GetUserQuery(id));
        return Ok(user);
    }
}

Features

  • Request/Response Pattern: Send requests and receive typed responses
  • Notifications: Publish notifications to multiple handlers
  • Pipeline Behaviors: Add cross-cutting concerns (logging, validation, etc.)
  • Dependency Injection: Seamless integration with Microsoft.Extensions.DependencyInjection
  • Assembly Scanning: Automatically discovers and registers handlers

Pipeline Behaviors

Add cross-cutting concerns using pipeline behaviors:

public class LoggingBehavior<TRequest, TResponse>
    : IPipelineBehavior<TRequest, TResponse>
    where TRequest : IRequest<TResponse>
{
    private readonly ILogger<LoggingBehavior<TRequest, TResponse>> _logger;

    public LoggingBehavior(ILogger<LoggingBehavior<TRequest, TResponse>> logger)
    {
        _logger = logger;
    }

    public async Task<TResponse> Handle(
        TRequest request,
        CancellationToken cancellationToken,
        RequestHandlerDelegate<TResponse> next)
    {
        _logger.LogInformation("Handling {RequestType}", typeof(TRequest).Name);
        
        var response = await next();
        
        _logger.LogInformation("Handled {RequestType}", typeof(TRequest).Name);
        
        return response;
    }
}

Notifications

Publish notifications to multiple handlers:

public sealed record UserCreatedEvent(int UserId, string UserName)
    : INotification;

public sealed class SendWelcomeEmailHandler
    : INotificationHandler<UserCreatedEvent>
{
    public Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
    {
        // Send welcome email
        return Task.CompletedTask;
    }
}

public sealed class UpdateUserCacheHandler
    : INotificationHandler<UserCreatedEvent>
{
    public Task Handle(UserCreatedEvent notification, CancellationToken cancellationToken)
    {
        // Update cache
        return Task.CompletedTask;
    }
}

// Publish the notification
await _mediator.Publish(new UserCreatedEvent(userId, userName));

License

MIT

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 is compatible. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on SimpleMediatorLib:

Package Downloads
Application.Abstraction

CQRS abstractions for .NET application layers using SimpleMediator and Core.Result.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 183 11/28/2025
1.0.1 416 11/18/2025
1.0.0 250 11/14/2025