C
C#•9mo ago
Deadman Mersh

MediatR pipeline problem: One Notification to three different handlers based on notification

I'm dead stuck on a problem. I'm working on a project and instead of looping through a bunch of if statements or switches to get the correct handler. I want to direct the notification to publish to the correct handler based on the property passed through. So say public class UpdateLogger : INotification { public Logger Message { get; set; } } public class UpdateLogger1Handler : INotification<UpdateLogger> { // Logic here } public class UpdateLogger2Handler : INotification<UpdateLogger> { // Logic here } public class UpdateLogger3Handler : INotification<UpdateLogger> { // Logic here } And lets say Logger has a property like LoggerId that designates basically which of these 3 handlers goes to what Bad design? Possible? The idea is that later on, all you'd have to do is add in a new handler to INotification<UpdateLogger> for a different publish.
9 Replies
Mayor McCheese
Mayor McCheese•9mo ago
IIRC there is a problem with MSDI and doing this This is supported by mediatr though. Oh, I think I misread AFAIK all the mediatr handlers would attempt to process, you'd have to have some sort of sieve on each one to exit early based on criteria.
Deadman Mersh
Deadman MershOP•9mo ago
I see, my current set up is just having an if check if the id matches. I was just looking to see if there was a way to hard route the notification prior to calling the handlers So it wouldn't run through them all
Mayor McCheese
Mayor McCheese•9mo ago
I'm not quite sure I understand
Deadman Mersh
Deadman MershOP•9mo ago
Haha sorry
Mayor McCheese
Mayor McCheese•9mo ago
I mean, I see what you're saying, but I don't see a lot of value to it, and I think you're just going to create hard to debug/reproduce issues.
Deadman Mersh
Deadman MershOP•9mo ago
Gotcha, I MEAN, it was just an idea, I'll also accept if people just think its not a good design 🙂
Mayor McCheese
Mayor McCheese•9mo ago
I think you're adding a lot of "surprise" You might want to look at mediatr behaviors
Deadman Mersh
Deadman MershOP•9mo ago
I'll do some more research, appreciate the feedback/advice!
Mayor McCheese
Mayor McCheese•9mo ago
still not quite what you'd be looking for, but might be a bit closer
Want results from more Discord servers?
Add your server