Using MediatR as a mediator
In this section, we are exploring MediatR, an open source mediator implementation. What is MediatR? Let's start with its maker's description from its GitHub repository, which brands it as this:
MediatR is a simple but very powerful tool for in-process communication through messaging. It supports a request/response flow through commands, queries, notifications, and events, synchronously and asynchronously. That resumes what the README says.
You can install the NuGet package using the .NET CLI: dotnet add package MediatR
.
Now that I have quickly introduced the tool, we are going to explore the migration of our Clean Architecture sample but use MediatR to dispatch the StocksController
requests to the core use cases. Let's jump into the code to see how it works.