ソーシャル ネットワーク Web サイトの設計に DDD (ドメイン イベントを含む) と CQRS (イベント ソーシングなし) を採用しています。
User
、FriendRequest
、のような集約ルートがありFriendship
ます。UserAddressChanged
、のようなドメイン イベントもありますFriendRequestAccepted
。これらのイベントの一部は、関係のあるユーザーに通知する必要があります。だから私は次のNotification
ようなクラスを持つことを考えています:
public enum NotificationReason
{
IncomingFriendRequest = 1,
OutgoingFriendRequestAccepted = 2,
// and many more ...
}
public class Notification
{
public long Id { get; set; }
public int UserId { get; set; }
public string UserName { get; set; }
public string AvatarUrl { get; set; }
public DateTime Timestamp { get; set; }
public NotificationReason Reason { get; set; }
public bool Read { get; set; } //if user has read this notification.
}
Notification
しかし、クラスを集約ルートとしてモデル化する必要がありますか? はいの場合、User
集約がアドレスを変更してUserAddressChanged
ドメイン イベントを発生させると、対応するイベント ハンドラで新しい集約Notification
が作成され、その後NotificationRepository
. しかし、イベント ハンドラーで新しい集計を作成するのは怪しいと思います。
一方、 のような単純なクラスには重すぎるようにも感じNotification
ます。通知がドメインの問題なのかインフラの問題なのか判断できません。