jbogard / MediatR

Simple, unambitious mediator implementation in .NET
Apache License 2.0
11.19k stars 1.18k forks source link

INotificationHandler #765

Closed kalyanthumaty closed 2 years ago

kalyanthumaty commented 2 years ago

I have read 1 notification can have N handlers, its a one to many relationship. In such case, what is the order that the handlers gets executed? Can we have a control to set the order of execution among handlers? Also, If I want to carry the output of one handler into another handler, or executing one handler based on the end result of another handler, is that possible?

eskaufel commented 2 years ago

You should not use events/notifications this way. The order depends on the implementation of the di-container used, and it can change when new versions are released.

KyMback commented 2 years ago

What about managing execution order in NotificationHandlerWrapperImpl? We can create our own implementation of this, but we can't use it because we create implementation via Activator + it's private method

image
kalyanthumaty commented 2 years ago

You should not use events/notifications this way. The order depends on the implementation of the di-container used, and it can change when new versions are released.

@eskaufel Thanks for your response but I did not quiet get you. Let me ask my questions in a different way by taking a use case below.

I have a customer who placed an order => OrderPlacedEvent : INotification

After the order is placed, I have to perform the following three actions

  1. Save the order details to DB => OrderPlacedSaveToDB : INotificationHandler
  2. Send email to customer => OrderPlacedEmailNotification : INotificationHandler
  3. Set the status to "OrderPlaced" => OrderPlacedSetStatus : INotificationHandler

Question #1: Can I use MediatR INotification like above. Question #2: If the answer is yes, then in what order are these handlers get invoked? Question #3: If the Handler#1 fails to do its job then the subsequent handlers should not be invoked. Is that possible?

Please respond. Thanks