MediatR

MediatR is a package message dispatcher within the application. It's useful for implementing requests/responses such as commands, queries, and handlers. Also, MediatR allows sending messages and especially supports various architectural patterns in modern .NET and .NET Core applications. It’s introduced as a .NET Standard library, starting from .NET Core 2.0, 3.1, and till supports the latest .NET 9.0. Also, it's an open-source, powerful library to implement the Mediator pattern in .NET applications. Architecture that supports mediatR is mentioned below.

MediatR Library

MediatR Features in .NET 9 Core

  1. .NET 9.0 minimal API and modular project structure enhancements in a better way
  2. Dynamic Database support provided for using the Entity Framework (SQL Server, PostgreSQL, MySQL, SQLite)
  3. Better developer experience in lightweight, testable service layers.
  4. MediatR is used for implementing CQRS and a separate layer like Application, Domain, and infrastructure.
  5. Event handling is improved with built-in support for Server-Sent Events (SSE),

Advantages of MediatR in the latest version of .NET

  1. Testability improved; unit test handlers are easy and isolated
  2. Good for large applications that maintain many modules and features
  3. Logging, Validation, and Caching are supported in Pipeline behaviours
  4. Efficient for real-time applications and event-driven applications, and streaming API like OpenAI’s