Reputation: 186
I am looking to get the best practice around DDD/CQRS principles for handing relationships between bounded contexts.
We have two BCs Property Management Context and Tenant Portal Context. We have the Home aggregate in the Tenant Portal context, which operates completely independent of the Property aggregate in the property management context. However, on creating a Home we are finding the need to store the PropertyId from the other BC in the initial event as a look-up.
I was initially of the opinion that event identity references across BCs were discouraged. However, someone in my team challenged that opinion and I'm struggling to find the resources that support either argument.
Is it considered acceptable to reference aggregate roots in other bounded contexts?
If it isn't recommended, would a better alternative be to purposefully obscure the relationship by trying to use context-specific language, such as LookUpCode or ExternalReferenceCode. Even though, there is a hidden implicit understanding that this is actually the PropertyId and unlikely be anything else for the near future.
Two different contrary suggestions I have seen to a similar question are:
Upvotes: 3
Views: 1438
Reputation: 59144
The suggestions you quote are not actually contradictory.
It's reasonable to use foreign IDs to reference entities defined in other contexts, but:
So, for instance if TenantPortal needs to perform certain actions or get certain information from PropertyMgmt, then TenantPortal.Home can contain a PropertyRef that it can use to do those things or get that information. It has no other purpose, and should not be (part of) an ID for anything in TenantPortal.
The fact that a PropertyRef is an entity ID in PropertyMgmt is irrelevant to TenantPortal.
Upvotes: 3