Or is that considered bad practice or something?
I have one notification triggers 4-5 handlers, which in turn call database to retrieve data. Each those calls can also be called separately, so they are request/handler themselves.
Thanks.
This is why MediatR became so popular. Developers love magic. Again, this is not a mediator pattern, but a service locator, an anti-pattern.
MediatR Requests are very simple request-response style messages, where a single request is synchronously handled by a single handler (synchronous from the request point of view, not C# internal async/await). Good use cases here would be returning something from a database or updating a database.
Jimmy Bogard (the author of mediatr) is saying you should avoid this.
See his blog post
https://lostechies.com/jimmybogard/2016/12/12/dealing-with-duplication-in-mediatr-handlers/
or this stack overflow question and answer https://github.com/jbogard/MediatR/issues/400
Also note that if you are using behaviors they will run multiple times. This could lead to inefficient code but of course it could also be what you want to happen :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With