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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With