Nast.SimpleMediator 1.1.0

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

SimpleMediator

A lightweight and efficient implementation of the Mediator pattern for .NET applications.

Support policy: ships a single net8.0 asset validated for .NET 8, .NET 9, and .NET 10.

Features

  • Request/response handling with typed results
  • Notifications with multiple handlers
  • Async stream requests via IAsyncEnumerable<T>
  • Dependency-injection integration for Microsoft.Extensions.DependencyInjection
  • Explicit handler registration for deterministic startup
  • Real pipeline behaviors through IPipelineBehavior<TRequest, TResponse>

Installation

dotnet add package Nast.SimpleMediator

Runtime Support

Validated support matrix: .NET 8, .NET 9, and .NET 10.

SimpleMediator publishes a single net8.0 package asset. Consumers on .NET 8/9/10 use that same asset, and release validation proves the package metadata, runtime matrix, and package contents stay aligned.

Registration

AddMediator() only registers the mediator core services. To discover handlers, pass the assemblies you want scanned explicitly.

using Nast.SimpleMediator;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddMediator(typeof(Program).Assembly);

builder.Services.AddMediator(options =>
{
    options.RegisterServicesFromAssemblies(typeof(Program).Assembly);
    options.AddBehavior<LoggingBehavior>();
});

Requests and Responses

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

public sealed class GetUserHandler : IRequestHandler<GetUserQuery, User>
{
    private readonly IUserRepository _repository;

    public GetUserHandler(IUserRepository repository)
    {
        _repository = repository;
    }

    public Task<User> Handle(GetUserQuery request, CancellationToken cancellationToken)
    {
        return _repository.GetByIdAsync(request.UserId);
    }
}

Notifications

public record UserCreatedNotification(int UserId, string Email) : INotification;

public sealed class EmailNotificationHandler : INotificationHandler<UserCreatedNotification>
{
    private readonly IEmailService _emailService;

    public EmailNotificationHandler(IEmailService emailService)
    {
        _emailService = emailService;
    }

    public Task Handle(UserCreatedNotification notification, CancellationToken cancellationToken)
    {
        return _emailService.SendWelcomeEmailAsync(notification.Email);
    }
}

Custom Pipeline Behaviors

Custom behaviors MUST implement IPipelineBehavior<TRequest, TResponse>.

public sealed class LoggingBehavior : IPipelineBehavior<GetUserQuery, User>
{
    private readonly ILogger<LoggingBehavior> _logger;

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

    public async Task<User> Handle(
        GetUserQuery request,
        RequestHandlerDelegate<User> next,
        CancellationToken cancellationToken)
    {
        _logger.LogInformation("Handling {RequestType}", typeof(GetUserQuery).Name);

        var response = await next();

        _logger.LogInformation("Handled {RequestType}", typeof(GetUserQuery).Name);
        return response;
    }
}

This keeps the behavior contract honest: the mediator resolves and executes IPipelineBehavior<TRequest, TResponse> instances in registration order around the real handler.

Breaking Changes in 1.1

  • Consumers that relied on ambient loaded-assembly scanning must switch to explicit assembly registration.
  • Legacy behavior abstractions that do not implement IPipelineBehavior<TRequest, TResponse> are no longer supported.
  • AddMediator() without assemblies is still valid, but it now registers only the mediator core services.

Migration Checklist

  1. Replace no-argument registration used for handler discovery with AddMediator(typeof(Program).Assembly) or RegisterServicesFromAssemblies(...).
  2. Replace custom behavior interfaces with concrete IPipelineBehavior<TRequest, TResponse> implementations.
  3. Keep package/runtime expectations aligned with the validated support matrix: .NET 8, .NET 9, and .NET 10.

License

This project is licensed under the MIT License. See LICENSE for details.

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.1.0 153 4/8/2026
1.0.2 252 7/9/2025
1.0.1 335 7/9/2025 1.0.1 is deprecated because it has critical bugs.
1.0.0 335 7/9/2025 1.0.0 is deprecated because it has critical bugs.

Support policy: ships a single net8.0 asset validated for .NET 8, .NET 9, and .NET 10.