As the question states, is this bad practice? I have a User aggregate root in the bounded context of Identity for authenticating the user. In this bounded contexts I have fields for the User related to identification of the User e.g. email, salted pw and so on.

I also have a generic subdomain for handling notifications. In this context a User is a Notificant. In this context, the Notificant has fields for e.g. the number of unread notifications, lastRead etc.

Is it good to reuse the User id in this case, as I know there is a 1-to-1 correspondence between a User and Notificant? Or should I have a field in the Notificant root referencing the User? It feels redundant, because then I have to make a lookup to map between them when I know their relationship is symmetric.

有帮助吗?

解决方案

No, don’t reuse aggregate root keys for identifying different objects in different contexts !

Why?

  • Because a Notificant is not a User. Maybe today, mostly users get notified. But tomorrow you may have to notify third parties who are not using the system, or even automatic monitoring systems.
  • Because it’s another bounded context, and bounded contexts may evolve independently. Maybe today User and Notificant share the same granularity and may be directly related one to one. But who knows about tomorrow? So you need to carefully think about how they should be related.
许可以下: CC-BY-SA归因
scroll top