Foundatio.Mediator.Abstractions 1.0.1

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

FoundatioFoundatio

Build status NuGet Version feedz.io Discord

Foundatio Mediator is a high-performance mediator library for .NET that uses source generators and C# interceptors to achieve near-direct-call performance with zero runtime reflection. Build completely message-oriented, loosely coupled apps that are easy to test β€” with zero boilerplate.

✨ Features

  • πŸš€ Near-direct call performance β€” source generators and interceptors eliminate runtime reflection
  • ⚑ Convention-based discovery β€” handlers discovered by naming conventions, no interfaces or base classes required
  • 🧩 Plain handler classes β€” sync or async, static or instance methods, any signature, multiple handlers per class
  • 🌐 Auto-generated API endpoints β€” Minimal API endpoints generated from handlers with route, method, and parameter binding inference
  • πŸ“‘ Streaming handlers β€” real-time Server-Sent Events on your API with just a handler method returning IAsyncEnumerable<T>
  • 🎯 Built-in Result<T> β€” rich status handling without exceptions, auto-mapped to HTTP status codes
  • πŸŽͺ Middleware pipeline β€” Before/After/Finally/Execute hooks with state passing and short-circuiting
  • πŸ”„ Cascading messages β€” tuple returns automatically publish follow-on events
  • πŸ”§ Full DI support β€” constructor and method parameter injection via Microsoft.Extensions.DependencyInjection
  • πŸ” Authorization β€” built-in attribute-based authorization with policy support
  • πŸ”’ Compile-time safety β€” analyzer diagnostics catch misconfigurations before runtime
  • πŸ§ͺ Easy testing β€” plain objects with no framework coupling
  • πŸ› Superior debugging β€” short, readable call stacks

πŸš€ Get Started

dotnet add package Foundatio.Mediator

Define a message and a handler β€” no interfaces or base classes required:

public record Ping(string Text);

public static class PingHandler
{
    public static string Handle(Ping msg) => $"Pong: {msg.Text}";
}

Wire up DI and call it:

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMediator();

var app = builder.Build();

app.MapGet("/ping", (IMediator mediator) =>
    mediator.Invoke<string>(new Ping("Hello")));

app.Run();

That's it. The source generator discovers handlers by naming convention at compile time β€” zero registration, zero reflection, near-direct-call performance.

Generate API endpoints

Handlers can automatically become API endpoints. Return Result<T> for rich HTTP status mapping:

public record CreateTodo(string Title);
public record GetTodo(int Id);

public class TodoHandler
{
    public Result<Todo> Handle(CreateTodo command) =>
        Result<Todo>.Created(new Todo(1, command.Title));

    public Result<Todo> Handle(GetTodo query) =>
        query.Id > 0 ? new Todo(query.Id, "Sample") : Result.NotFound();
}
app.MapMediatorEndpoints();
POST /api/todos       β†’ 201 Created
GET  /api/todos/{id}  β†’ 200 OK / 404 Not Found

Routes, HTTP methods, parameter binding, and OpenAPI metadata are all inferred from your message names and Result factory calls.

πŸ‘‰ Getting Started Guide β€” step-by-step setup with code samples for ASP.NET Core and console apps.

πŸ“– Complete Documentation

πŸ“‚ Sample Applications

Explore complete working examples:

  • Console Sample - Simple command-line application demonstrating handlers, middleware, and cascading messages
  • Clean Architecture Sample - Modular monolith showcasing:
    • Clean Architecture layers with domain separation
    • Repository pattern for data access
    • Cross-module communication via mediator
    • Domain events for loose coupling
    • Auto-generated API endpoints
    • Shared middleware across modules

πŸ“¦ CI Packages (Feedz)

Want the latest CI build before it hits NuGet? Add the Feedz source (read‑only public) and install the pre-release version:

dotnet nuget add source https://f.feedz.io/foundatio/foundatio/nuget -n foundatio-feedz
dotnet add package Foundatio.Mediator --prerelease

Or add to your NuGet.config:

<configuration>
    <packageSources>
        <add key="foundatio-feedz" value="https://f.feedz.io/foundatio/foundatio/nuget" />
    </packageSources>
    
    <packageSourceMapping>
        <packageSource key="foundatio-feedz">
            <package pattern="Foundatio.*" />
        </packageSource>
    </packageSourceMapping>
</configuration>

CI builds are published with pre-release version tags (e.g. 1.0.0-alpha.12345+sha.abcdef). Use them to try new features earlyβ€”avoid in production unless you understand the changes.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. See our documentation for development guidelines.

@martinothamar/Mediator was the primary source of inspiration for this library, but we wanted to use source interceptors and be conventional rather than requiring interfaces or base classes.

Other mediator and messaging libraries for .NET:

  • MediatR - Simple, unambitious mediator implementation in .NET with request/response and notification patterns
  • MassTransit - Distributed application framework for .NET with in-process mediator capabilities alongside service bus features
  • Immediate.Handlers - another implementation of the mediator pattern in .NET using source-generation.

πŸ“„ License

Apache-2.0 License

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 was computed. 
.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 Foundatio.Mediator.Abstractions:

Package Downloads
Foundatio.Mediator

A fast, convention-based C# mediator library using incremental source generators

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 152 3/11/2026
1.0.0 131 3/11/2026
1.0.0-rc.15 33 3/11/2026
1.0.0-rc.14 32 3/10/2026
1.0.0-rc.13 119 3/4/2026
1.0.0-rc.12 45 3/4/2026
1.0.0-rc.11 124 2/24/2026
1.0.0-rc.10 48 2/24/2026
1.0.0-rc.9 277 2/4/2026
1.0.0-rc.8 89 2/3/2026
1.0.0-rc.6 216 1/20/2026
1.0.0-rc.5 334 1/8/2026
1.0.0-rc.4 1,422 12/11/2025
1.0.0-rc.3 303 11/6/2025
1.0.0-rc.2 117 11/1/2025
1.0.0-rc.1 125 10/19/2025
1.0.0-preview13 177 10/18/2025
1.0.0-preview12 222 9/21/2025
1.0.0-preview11 361 9/17/2025
1.0.0-preview.14 96 10/19/2025
Loading failed