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
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
I'm not quite sure I understand
Haha sorry
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.
Gotcha, I MEAN, it was just an idea, I'll also accept if people just think its not a good design 🙂
I think you're adding a lot of "surprise"
You might want to look at mediatr behaviors
I'll do some more research, appreciate the feedback/advice!
still not quite what you'd be looking for, but might be a bit closer