I'm designing a C# layered application and I'd like to know if it is okay for my Domain Objects to know about the Repositories and the ServiceLayer.
If not - how do I solve complex functions like Article.CalculatePrice() or Offer.CalculatePrice, which should IMHO iterate through all items and summarice Item.GetPrice().
I"m using EF5 btw.
UPDATE: My scenario is as followed: I have to build this on top of a legacy DB that doesn't follow any imaginable rules and some kind of bizarre price calculation scenarios:
e.g. I have an Article A { Type: Curtain, Color: Blue, Dimension: 200cm }
, but there is no article with a specific price defined in the DB -> so I have to look in so called PriceGroups
which pricebuilding rules apply.
There may for example be the following groups that apply to the article:
- Article A { Type: Curtain, Color: Blue, Dimension: 200cm } <-- does not exist
- PriceGroup { Type: Curtain, Color: Blue, Dimension: NULL, Price: -5 EUR (*relative* price) }
- PriceGroup { Type: Curtain, Color: NULL, Dimension 200cm, Price 25 EUR (*absolute* price) }
The thing is: PriceGroup and Article can not be aggregated in any way, and the price groups are not aligned hierachical, but they apply by specification.
So: IMHO the ArticlePriceService has to know about PriceGroups, hence if no ArticlePrice can be found, it has to return a Price calculated from the groups. So, if I box this whole thing in a Domain Object, my ArticleDO would have to know about the ArticlePriceService, which has to know about the PriceGroupService?
I'm really confused how to solve this problem. Please try to provide an example or me..