Mediatr: IRequestHandlers vs INotificationHandler

Created on 27 Apr 2017  Â·  2Comments  Â·  Source: jbogard/MediatR

Please excuse my trivial question, but I'm a little unsure about the major differences between IRequestHandler

The interface methods looks fairly similar.

  • INotificationHandlervoid Handle(TNotification notification);
  • IRequestHandlervoid Handle(TRequest message);

They also both seem applicable for fire & forget scenarios. When exactly would you use notifications over void returning requests? I'm probably missing something very blatant here.

Most helpful comment

Requests are for:

1 request to 1 handler. Handler may or may not return a value

Notifications are for:

1 notification to n handlers. Handler may not return a value.

In practical terms, requests are "commands", notifications are "events".
Command would be directing MediatR to do something like
"ApproveInvoiceCommand -> ApproveInvoiceHandler". Event would be
notifications, like "InvoiceApprovedEvent ->
SendThankYouEmailToCustomerHandler"

HTH

On Thu, Apr 27, 2017 at 2:27 PM, Cecil Phillip notifications@github.com
wrote:

Please excuse my trivial question, but I'm a little unsure about the major
differences between IRequestHandler and INotificationHandler.

The interface methods looks fairly similar.

They also both seem applicable for fire & forget scenarios. When exactly
would you use notifications over void returning requests? I'm probably
missing something very blatant here.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/jbogard/MediatR/issues/163, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGYMiD48W1u2NTwltpqvnwmP_YneIWaks5r0OwGgaJpZM4NKqcy
.

All 2 comments

Requests are for:

1 request to 1 handler. Handler may or may not return a value

Notifications are for:

1 notification to n handlers. Handler may not return a value.

In practical terms, requests are "commands", notifications are "events".
Command would be directing MediatR to do something like
"ApproveInvoiceCommand -> ApproveInvoiceHandler". Event would be
notifications, like "InvoiceApprovedEvent ->
SendThankYouEmailToCustomerHandler"

HTH

On Thu, Apr 27, 2017 at 2:27 PM, Cecil Phillip notifications@github.com
wrote:

Please excuse my trivial question, but I'm a little unsure about the major
differences between IRequestHandler and INotificationHandler.

The interface methods looks fairly similar.

They also both seem applicable for fire & forget scenarios. When exactly
would you use notifications over void returning requests? I'm probably
missing something very blatant here.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/jbogard/MediatR/issues/163, or mute the thread
https://github.com/notifications/unsubscribe-auth/AAGYMiD48W1u2NTwltpqvnwmP_YneIWaks5r0OwGgaJpZM4NKqcy
.

Gotcha. Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

developermj picture developermj  Â·  6Comments

ArturKarbone picture ArturKarbone  Â·  3Comments

orantwolinkme picture orantwolinkme  Â·  4Comments

mdmoura picture mdmoura  Â·  4Comments

TheRubble picture TheRubble  Â·  5Comments