Foundatio.Mediator
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package Foundatio.Mediator --version 1.0.0
NuGet\Install-Package Foundatio.Mediator -Version 1.0.0
<PackageReference Include="Foundatio.Mediator" Version="1.0.0" />
<PackageVersion Include="Foundatio.Mediator" Version="1.0.0" />
<PackageReference Include="Foundatio.Mediator" />
paket add Foundatio.Mediator --version 1.0.0
#r "nuget: Foundatio.Mediator, 1.0.0"
#:package Foundatio.Mediator@1.0.0
#addin nuget:?package=Foundatio.Mediator&version=1.0.0
#tool nuget:?package=Foundatio.Mediator&version=1.0.0
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.
π 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.
π Related Projects
@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 | Versions 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. |
-
.NETStandard 2.0
- Foundatio.Mediator.Abstractions (>= 1.0.0)
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.1 | 95 | 3/11/2026 |
| 1.0.0 | 99 | 3/11/2026 |
| 1.0.0-rc.15 | 42 | 3/11/2026 |
| 1.0.0-rc.14 | 36 | 3/10/2026 |
| 1.0.0-rc.13 | 103 | 3/4/2026 |
| 1.0.0-rc.12 | 44 | 3/4/2026 |
| 1.0.0-rc.11 | 121 | 2/24/2026 |
| 1.0.0-rc.10 | 59 | 2/24/2026 |
| 1.0.0-rc.9 | 289 | 2/4/2026 |
| 1.0.0-rc.8 | 127 | 2/3/2026 |
| 1.0.0-rc.6 | 261 | 1/20/2026 |
| 1.0.0-rc.5 | 408 | 1/8/2026 |
| 1.0.0-rc.4 | 1,403 | 12/11/2025 |
| 1.0.0-rc.3 | 304 | 11/6/2025 |
| 1.0.0-rc.2 | 121 | 11/1/2025 |
| 1.0.0-rc.1 | 112 | 10/19/2025 |
| 1.0.0-preview13 | 135 | 10/18/2025 |
| 1.0.0-preview12 | 181 | 9/21/2025 |
| 1.0.0-preview11 | 324 | 9/17/2025 |
| 1.0.0-preview.14 | 93 | 10/19/2025 |