質問

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.

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top