MediatR
MediatR copied to clipboard
INotificationHandler
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?
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.
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
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
- Save the order details to DB => OrderPlacedSaveToDB : INotificationHandler<OrderPlacedEvent>
- Send email to customer => OrderPlacedEmailNotification : INotificationHandler<OrderPlacedEvent>
- Set the status to "OrderPlaced" => OrderPlacedSetStatus : INotificationHandler<OrderPlacedEvent>
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