This .NET 7.0 solution demonstrates the Mediator design pattern through two parallel implementations of a chat application. The MediatorChatConsoleApp project provides a manual implementation where a ChatMediator class registers users and routes messages between them, demonstrating the core concept of decoupling communication between components through a central mediator object.
The MediatrConsoleApp project implements the same chat functionality using the popular MediatR NuGet library (v12.2.0) with Microsoft.Extensions.DependencyInjection. It uses IRequest and IRequestHandler<T> to dispatch ChatMessage requests through the mediator pipeline, showcasing an enterprise-ready approach with full async support and dependency injection integration. Comparing the two implementations side by side highlights the trade-offs between simplicity and scalability when choosing between manual and library-based mediator patterns.
- .NET 7.0 SDK or later
cd MediatorDesignPatternExamples/MediatorChatConsoleApp
dotnet runIf you found this useful and you want to learn more about C#, .NET, and software engineering, subscribe to the free Dev Leader Weekly newsletter:
Subscribe to Dev Leader Weekly
- All Links
- Website - Dev Leader
- YouTube - Dev Leader
- YouTube - Dev Leader Path To Tech
- YouTube - Dev Leader Podcast
- YouTube - CodeCommute
- Newsletter - Dev Leader Weekly
- LinkedIn - Nick Cosentino
- GitHub - ncosentino
- Twitter/X - Dev Leader
- Threads - Dev Leader
- Bluesky - Dev Leader
- Mastodon - Dev Leader
- Facebook - Dev Leader
- TikTok - Dev Leader
- Twitch - Dev Leader
- Stack Overflow - Nick Cosentino
Powered by BrandGhost 👻