Pelican.Mediator 2.0.0

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

Pelican.Mediator

Simple, fast, reliable message delivery for .NET.

Build NuGet License: MIT

Pelican.Mediator is a lightweight Mediator pattern implementation for .NET applications. It supports request handlers, notifications, dependency injection, pipeline behaviors, pre-processors, and post-processors.

Packages

dotnet add package Pelican.Mediator
dotnet add package Pelican.Testing

Both packages target:

  • net8.0
  • net9.0
  • net10.0

Quick Start

Create a request and handler:

public sealed record Ping(string Message) : IRequest<string>;

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

Register Pelican:

services.AddPelican(typeof(PingHandler).Assembly);

Send a request:

public sealed class Generator
{
    private readonly IMediator _mediator;

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

    public async Task Invoke()
    {
        var response = await _mediator.Send(new Ping("Ping"));
        Console.WriteLine(response);
    }
}

Notifications

public sealed record CustomerCreated(string Name) : INotification;

public sealed class WelcomeEmailHandler : INotificationHandler<CustomerCreated>
{
    public Task Handle(CustomerCreated notification, CancellationToken cancellationToken = default)
    {
        Console.WriteLine($"Welcome {notification.Name}");
        return Task.CompletedTask;
    }
}

Publish the notification:

await mediator.Publish(new CustomerCreated("Ada"));

Pipelines

Pipeline behaviors wrap the handler execution:

public sealed class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest, TResponse>
{
    public async Task<TResponse> Handle(
        TRequest request,
        Handler<TResponse> next,
        CancellationToken cancellationToken = default)
    {
        Console.WriteLine($"Handling {typeof(TRequest).Name}");
        var response = await next(cancellationToken);
        Console.WriteLine($"Handled {typeof(TRequest).Name}");
        return response;
    }
}

Register behaviors with dependency injection:

services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));

Requests without a response use Pelican.Mediator.Void as the pipeline response type:

public sealed class AuditCommandBehavior<TRequest> : IPipelineBehavior<TRequest, Pelican.Mediator.Void>
    where TRequest : IRequest
{
    public Task<Pelican.Mediator.Void> Handle(
        TRequest request,
        Handler<Pelican.Mediator.Void> next,
        CancellationToken cancellationToken = default)
        => next(cancellationToken);
}

Pre-Processors and Post-Processors

public sealed class LoggingPreProcessor<TRequest> : IPreProcessor<TRequest>
{
    public Task Handle(TRequest request, CancellationToken cancellationToken = default)
    {
        Console.WriteLine("Before handler");
        return Task.CompletedTask;
    }
}
public sealed class LoggingPostProcessor<TRequest, TResponse> : IPostProcessor<TRequest, TResponse>
{
    public Task Handle(TRequest request, TResponse response, CancellationToken cancellationToken = default)
    {
        Console.WriteLine("After handler");
        return Task.CompletedTask;
    }
}

Register processors:

services.AddTransient(typeof(IPreProcessor<>), typeof(LoggingPreProcessor<>));
services.AddTransient(typeof(IPostProcessor<,>), typeof(LoggingPostProcessor<,>));

Pelican.Testing

Pelican.Testing provides a test dispatcher and trace assertions for request dispatch, handler resolution, pipeline behavior, replacement handlers, failures, and no-response requests.

Register handlers from one or more assemblies:

services.AddPelicanTesting(typeof(CreateCustomerCommandHandler).Assembly);

Send a request through the test dispatcher:

var provider = services.BuildServiceProvider();
var pelican = provider.GetRequiredService<IPelicanTesting>();

var response = await pelican.SendAsync(command);

Replace a handler for tests:

services.ReplacePelicanHandler<CreateCustomerRequest, CustomerResponse, FakeHandler>();

Inspect and assert the dispatch trace:

var trace = pelican.Trace;

trace.ShouldHandle<CreateCustomerRequest, CustomerResponse>();
trace.ShouldContainBehavior<ValidationBehavior<CreateCustomerRequest, CustomerResponse>>();
trace.ShouldRunBehaviorBefore<ValidationBehavior<CreateCustomerRequest, CustomerResponse>, HandlerExecution>();

No-response requests are supported:

await pelican.SendAsync(new RebuildCustomerIndex());

pelican.Trace.ShouldHandle<RebuildCustomerIndex>();

External test hosts can integrate Pelican testing with a small wrapper:

public static class TestHostPelicanExtensions
{
    public static IServiceCollection UsePelicanTesting(
        this IServiceCollection services,
        params Assembly[] assemblies)
        => services.AddPelicanTestingAdapter(assemblies);
}
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 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 is compatible.  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 (9)

Showing the top 5 NuGet packages that depend on Pelican.Mediator:

Package Downloads
TurtlePath

Main TurtlePath package with handler foundations, hooks, request/response models, and application errors.

TurtlePath.Automations

Declarative automation profiles and generated handler registration for TurtlePath application flows.

TurtlePath.Testing

Testing harness, fake adapters, and in-memory storage helpers for TurtlePath handlers and automations.

TurtlePath.Spider

Spider pipeline extensions for dispatching Pelican requests through TurtlePath applications.

Krackend.Sagas.Orchestrations.ControlPlane.Application

Control-plane application layer for Krackend saga orchestration design, distribution, and security workflows.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.0 1,303 8/7/2026
1.1.2 8,077 5/28/2025
1.1.1 194 5/24/2025
1.0.5 165 5/24/2025
1.0.4 234 5/23/2025