有讀者來信詢問關於INotification
使用時機,以及為什麼不直接全部使用IRequestHandler
就好,看了一下之前的文章,應該是表達得不夠清晰,稍微再補充一下。
IRequestHandler
主要差別總結:INotification
本身是一種EventBus
的概念,並不會回傳結果,相當適用於我們執行一項命令後,希望執行一些後續處理,而這些處理不一定要包含在我們當前的上下文中,這樣可以將每種執行邏輯獨立分開。例如我們註冊會員後,還有一些想執行的程序,如寄送會員成功註冊信、新會員註冊購物金等
Event
或Notification
為結尾internal record UserRegisteredNotification : INotification
{
public string Email { get; init; } = null!;
}
// OR
internal record UserRegisteredEvent : INotification
{
public string Email { get; init; } = null!;
}