explaingit

luckypennysoftware/mediatr

11,832C#Audience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((MediatR))
    What it does
      In-process messaging
      Decouples components
      Routes to handlers
    Message types
      Requests with response
      Notifications
      Streaming responses
    Features
      Pipeline behaviors
      DI integration
      Assembly scanning
    Audience
      NET developers
      Backend engineers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Send commands and queries through a central mediator instead of calling services directly, reducing tight coupling in your .NET application.

USE CASE 2

Add cross-cutting behaviors like logging, validation, or performance tracing to all requests without modifying individual handler code.

USE CASE 3

Publish events that multiple handlers respond to independently, replacing direct method calls with a decoupled notification pattern.

Tech stack

C#.NET

Getting it running

Difficulty · easy Time to first run · 30min

Commercial use requires a paid license key from MediatR.io, open-source projects can use it free.

Free for open-source projects, but a paid license key from MediatR.io is required for commercial applications.

In plain English

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.

Copy-paste prompts

Prompt 1
I'm building a .NET 8 web API and want to use MediatR to separate command handlers from controllers. Show me how to register MediatR, create a CreateOrderCommand with a handler, and dispatch it from a controller action.
Prompt 2
I want to add a validation pipeline behavior to MediatR in my ASP.NET Core app using FluentValidation. Write the behavior class and show how to register it so it runs before every request handler.
Prompt 3
My MediatR app needs to log the execution time of every request. Write a pipeline behavior that measures elapsed time and logs it using ILogger.
Prompt 4
I need to add a MediatR commercial license key to my .NET project. Where exactly in the registration code do I set it, and what happens at runtime if I omit it?
Open on GitHub → Explain another repo

← luckypennysoftware on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.