DDD - Dependencies between domain model, services and repositories

前端 未结 6 2058
旧时难觅i
旧时难觅i 2020-12-23 10:32

Just wanted to know how others have layered their architecture. Say I have my layers as follows:

Domain Layer
--Product
--ProductService (Should the imp go

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-23 11:20

    If I understand your question correctly, you state that your Product class is calling the ProductService class. It shouldn't. You should do this in a factory class that is responsible for creating and configuring a Product. Where you call this method may also depend on when you want to issue the ProductId: We have what may be a similar case in that we need to get a number from our legacy accounting system for a project. I defer getting the number until the project is persisted so that we don't waste any numbers or have gaps. If you're in a similar situation, you may want to issue the ProductId in a repository save method instead of when the object is created.

    As an aside, do you really think you'll ever have more than one ProductService or ProductRepository? If not then I wouldn't bother with the interfaces.

    Edited to add:

    I recommend starting small and keeping it simple by starting with two just classes, Product and ProductServices. ProductServices would perform all services, including factory and repository, since you can think of those as specialized services.

提交回复
热议问题