gitmyhub

MediatR

C# ★ 12k updated 8d ago

Simple, unambitious mediator implementation in .NET

A .NET library that routes messages between different parts of your application through a central mediator instead of direct calls, keeping your codebase loosely coupled and easy to test.

C#.NETsetup: easycomplexity 2/5

MediatR is a library for .NET applications that acts as an in-process message broker. Rather than having one part of your application call another part directly, you send a message through MediatR and it routes the message to the appropriate handler. This keeps different parts of your code from depending on each other directly.

The library handles several types of messages. Requests are messages where you expect a single response back, useful for commands (do something and tell me the result) and queries (fetch something and return it). Notifications are messages that can be handled by multiple handlers at once, useful for events where several parts of the application need to react. It also supports streaming responses for scenarios where data comes back in chunks rather than all at once.

MediatR integrates with the standard .NET dependency injection system and can be registered with a single call. It scans your assemblies for handler classes and wires them up automatically. You can also add pipeline behaviors, which are pieces of code that run before or after every request, useful for logging, validation, or performance measurement without adding that logic to your handler code.

The library is installed via NuGet and has no external dependencies. Everything runs in-process, meaning messages stay within the same running application rather than being sent over a network. Starting from this version, a license key is required for commercial use. The key can be set during registration or directly on the Mediator class, and license keys are available at MediatR.io.

Where it fits