开发者

Root Entity reference to another root

开发者 https://www.devze.com 2023-03-04 09:38 出处:网络
I\'m facing a typical DDD problem. It must be very basic. I have an order and customer. A customer can create multiple orders. Customer is the root of its own aggregat开发者_运维百科e. Order is the ro

I'm facing a typical DDD problem. It must be very basic. I have an order and customer. A customer can create multiple orders. Customer is the root of its own aggregat开发者_运维百科e. Order is the root of its own aggregate. But when a customer creates an order, we display some portion of the customer information on the order. Should Order aggregate hold reference to customer? When it holds it then when the Order Repository gets the order, we are able to retrieve some portion of customer information as well for display. But when we involve the order in a transaction, customer also gets into it which is creating problem if the customer is also getting updated at the same time. Please advise guys ! My gut feeling says I MUST not hold reference to customer from order.

  • Question 2: (NEW)

Can I get and hold a reference to the Customer (from Customer Repository) for a given Order while creating an Order (using Order Factory) and safely save the Order (without updating the Customer inside in anyway, Customer is there only for information/query?) without creating contention if the same Customer is getting modified else where? Lets assume NHibernate as ORM.


A simple answer will be that you hold the ID of the customer or, if needed for your domain some ValueObject with a minimal set of information about the customer ( ID, Name ).

A more complex answer is to think about Bounded Context. See Eric Evans's presentation where he wishes he had put the BC chapter as the first chapter in the book.

The idea is that in your Customer Management Bounded Context, your Customer entity can be the AR of the Customer Aggregate and the Orders can be entities in the Customer Aggregate. In the Billing Bounded Context you can have an Order AR with a Customer entity inside.

0

精彩评论

暂无评论...
验证码 换一张
取 消