Quantcast
Channel: User Álvaro García - Software Engineering Stack Exchange
Viewing all articles
Browse latest Browse all 41

How to update a child entity of an aggregate root when I modify a property in another aggregate root?

$
0
0

I have one bounded conext, offers, that has Offers as root aggregate and Items as child entity.

I have another bounded context, products, which has Products as root aggregate, Providers as another root entity... but for the example Products is the entity that I need.

Product has a price property, that is the reference price that a product is sold. So when I add a new item to the offer, is this price which is set as default.

My offer is created in a first state, created, in which I can edit the offer, add new items, update items and so on.

I would like that if I change the price in a product, I would like to update the price in all the items of this product in all the offers which state is created.

How could I ensure that all the data is coherent after changing the price i the product, because they are two different bounded context, and two different aggregate roots, so from products I can't update the items of an offer when I call the update method in the product entity.

Also, I am organizing my project in modules according to the folder by feature (folder by bounded context) point of view, instead of folder by type, I think it is more clear. It is possible to see different opinions here: Folder-by-type or Folder-by-feature

So my project is organize in this way:

  • MyProject.Products.AplicationLayer

  • MyProject.Products.Domain

  • MyProject.Products.Repository

  • MyProject.Orders.AplicaionLayer

  • MyProject.Orders.Domain

  • MyProject.Orders.repository

I guess I have to have a higher layer or service that has a repository with offers, items and products, and do all in a same transaction. But in this way, I have a service only to update the price and the rest of the logic about products are in its own project, so the code is in many places, and I would like to avoid this.

Perhaps I have defined in a wrong way my bounded context, perhaps I could have a product entity in the offers bounded context only with the price, to only can modify the price that is the data that it is needed for the offer, but I think that this could make to update part of the product outside from many bounded context and i am not if it is correct.

Also with this solution, I don't see clear how could I update both entities in a coherence way, because I still would have two repositories, one for the root aggregate Offers and another repository for the root aggregate Products, because if I am not wrong, the recomendation it is to have one repository for each root aggregate, so in this case, no matter if I have a root aggregate Products in the bounded context of Offers, I still would have two repositories, and the main problem is how to ensure the transaction.

Or perhaps prices it wouldn't be a property of Products entity, because the price is more data that belongs to contability or sells (Offers in this case), more than products. But still I would have the problem to have two repositories for two root aggreagates.

I summary, I would like to know how could I update the price of the items in created offers when I update the price in the product.

Thanks.


Viewing all articles
Browse latest Browse all 41

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>