MediatR is a simple mediator pattern implementation in .NET as it keeps things separated and contributes to Single Responsibility Principle.
And CQRS stands for Command and Query Responsibility Segregation, which results in a pattern separating both read and write to maximize performance and scalability.
MediatR has 2 types of messages:
- Request and response messages that will dispatch a single handler
- Notification messages that will dispatch multiple handlers
Requests describe your commands and query behavior as they are fairly simple and specific.
Handler is what you will need to manage/solve a request. Where each request has its own handler.
Commands are where you will perform Insert, Update, and Delete operations.
Queries are where you will perform read operations only.
Notifications is where you will manage/solve a single request by using multiple handlers. So in this case you will create a notification message and create the corresponding handlers for your notification.
Remember that you should know the engineering functionalities of your application and based on it decide whether to use a request/response message or notification message. And more importantly, do not try to mix and match these 2 types of messages as you wish because you will break the mean of these patterns.
So my question is why would you need to call a command from the notification handler? and why do you want to mix 2 commands? and why would you mix the read and writes of your application?
If you understand the 2 types of messaging in MediatR you will know the answer to your question and for any future questions
Some great Resources:
Use MediatR in ASP.NET or ASP.NET Core
Intro to MediatR - Implementing CQRS and Mediator Patterns
Clean ASP.NET Core API using MediatR and CQRS | Setup
This video talks about notifications: The 2 MediatR features people don't know about but should
Customer List
and need this method in multiple Command Handler . what can i do? copy/pase this method in all Command Handlers? – Neuroglia