Skip to main content
.NETStandard2.0

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

Published
Mar 10, 2026
7mo ago
Total Downloads
22.4K
22,447

Install

dotnet add package Foundatio.Mediator --version 1.0.0-rc.14
ProductVersions
.NET Standard
netstandard2.0

README

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* β€” 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

πŸ‘‰ 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>
    <!-- Optional: limit this source to Foundatio packages -->
    <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

Changes from Previous Version

No structural changes between v1.0.0-rc.13 and v1.0.0-rc.14.

Adoption Assessment

A verified publisher signal is available. Assess fit from the package's supported frameworks, license and dependency graph rather than popularity alone.

This version is marked prerelease. Validate its API and upgrade path before production use.Compatibility metadata lists 1 target framework; confirm the exact target used by your application.

Related Guides & Workflows

Learn how to evaluate, integrate, or audit this package in your .NET project.