DDD - How to implement factories [closed]

心不动则不痛 提交于 2019-12-10 13:29:23

问题


I would like to know how to implement factories in domain driven design. (examples)

Where should be placed interfaces and implementations of factories ? Do I need to create interfaces for Domain objects which factories creating ? Do I need to create factories for repositories, services, ...

I am using Dependency Injection Containers how can I put them together with factories ?

Thanks.


回答1:


Factories should be simple classes, usually static. They can also be implemented as static methods on the entity or value object they create. Factories should create domain objects directly and only domain objects. Moreover, factories should not be tied with dependency injection because domain objects shouldn't have dependencies injected into them.

Domain objects should not implement interfaces - that is a needless abstraction.

Services and repository implementations on the other hand do have dependencies and should be created by the DI container.



来源:https://stackoverflow.com/questions/15299970/ddd-how-to-implement-factories

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!