Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best place for Dependency Injection In Domain Driven Design

in the context of DDD, I understand that application service orchestrates domain Service and Repository(application workflow), now my question is which layer responsible to inject the dependencies, is dependency injection must be done in UI(the layer that uses application service) or in Application Service . for example, in the case of concrete repository injection Which layer should do that?

another question is, can I place application service code directly in web service and use that web service as application service layer?

Best Regards

like image 271
Babak Golkar Avatar asked Jan 10 '18 06:01

Babak Golkar


1 Answers

... is dependency injection must be done in UI(the layer that uses application service) or in Application Service . for example, in the case of concrete repository injection Which layer should do that ?

Dependency injection container should be used as high as possible. In general, this means in the bootstrap of the application, even before the UI.

for example, in the case of concrete repository injection Which layer should do that ?

The layer that was first called, the entry point to the entire application, in the Composition root.

another question is, can I place application service code directly in web service and use that web service as application service layer?

It depends a lot on your architecture and on what is a "web service" for you. If you are referring to a layered architecture: If it is something like a REST controller then NO, in this case the "web service" is in the Presentation layer and the Application service is in the Application layer. The Application layer contains all the use cases, every Application service is a use case. Read more here.

like image 59
Constantin Galbenu Avatar answered Oct 14 '22 02:10

Constantin Galbenu