IoC Containers and Domain Driven Design

后端 未结 3 530
时光取名叫无心
时光取名叫无心 2021-02-02 15:50

I\'ve been searching for guidance for using IoC containers in domain driven design. Evan\'s book unfortunately doesn\'t touch on the subject. The only substantial guidelines I c

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-02 16:07

    In my opinion he is correct about not using IoC container in domain model. That practice I follow myself as well. Basic idea is that services may contain infrastructure dependencies and therefore its wise to mock them. Domain entities don't have those, so its not important to mock them up (still coding to interfaces is good practice).

    Factories for domain entities should not be in IoC container, but factories for services should. Basically you may reference entity factories in your services. It's not very tight coupling.

    Good reading about IoC can be found at Billy McCafferty's blog post "Dependency Injection 101"

提交回复
热议问题