Question:
- If I have to fetch an entity from another Bounded Context in order to map it to something in this Bounded Context, how would I go about doing that?
- Do I call the foreign Bounded Context's Application Layer? Perhaps I need a new "Query" Application Layer for such queries?
- Do I call foreign Bounded Context's repositories?
- Do I call foreign Bounded Context's Domain model directly?
Domain model (please note two separate Bounded Contexts):
CustomerContext.Customer
- this is the complete Customer model.ConsentContext.Person
- a scaled-down, heavily transformed version of multiple instances ofCustomerContext.Customer
. Rules guiding this transformation reside inConsentContext.Person
.Person
never references ˙Customer` directly, no dependency here.- Please note: these two entities most definitely belong to separate Bounded Contexts. Customer is what the business works with on a daily basis. Consent Person is heavily transformed due to legal and business requirements and has a different structure altogether. Customer is merely a data source, so Person can create itself using internal business logic.
Application Layer:
ConsentContext.ApplicationService
- implements use cases. As part of those use cases it fetchesConsentContext.Person
through somePersonRepository
.
Repos:
ConsentContext.PersonRepository
has to get in touch with theCustomerContext
and retrieve theCustomerContext.Customer
and map to a new Person. This is where I am coming up short - what do I call from here?CustomerContext
's Application Layer?CustomerContext
's repositories?CustomerContext
's Domain model directly?
Other:
- Both Bounded Contexts run in the same process, I am not using a REST API.
- I am targeting Customer/Supplier relationship.
Person
created? Generally, repositories are used to persist/load your model, not create it. IsPersonRepository.find( customerId )
not possible? These two entities seem like they may share an ID. That is, traditionally, how aggregates/entities are referenced between contexts.Person
anywhere. It is reconstituted every time anew, based on thecustomerId
andCustomer
. We do storePerson
in a dedicated database, however.Person
requires one or two separateCustomer
's to be created. There is a complex relationship between customers (typical example: two customers belong to the same account: one might be an account owner, but the other one might be relevant for Consent gathering, due to various legal reasons). So it is not that simple to mapCustomer
toPerson
- we mainly take both customersname
,id
,VAT
, whether they are business or residential and then use these to instatiate aPerson
(based on person internal logic, in ctor). Instantiation is done inPersonRepository
.