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:
”Simple, unambitious mediator implementation in .NET”
MediatR is a simple but very powerful tool doing in-process communication through messaging. It supports a request/response flow through commands, queries, notifications, and events, synchronously and asynchronously.
We 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, instead, use MediatR to dispatch the StocksController
requests to the core use cases. We use a similar pattern with MediatR to what we built in the CQS project.
Why migrate our Clean Architecture sample? The primary reason we are building the same project...