I am employing DDD (including domain events) and CQRS (without Event Sourcing) in the design of a social network website.
I have aggregate roots like User
, FriendRequest
, Friendship
. I also have domain events like UserAddressChanged
, FriendRequestAccepted
. Some of these events needs to be notified to concerning users. So I am thinking of having a Notification
class, something like:
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.
}
But should I model the Notification
class as an aggregate root? If yes, when the User
aggregate changes address and it raises a UserAddressChanged
domain event, in the corresponding event handler, a new aggregate Notification
will be created and subsequently saved via a NotificationRepository
. But creating new aggregates in event handlers sounds fishy to me.
Meanwhile, I also feel it is too heavy-weight for a simple class like Notification
. I cannot decide if notification is a domain concern or infrastructural concern.