Injection of Dependencies Layers Application / Domain / Repository

Asked

Viewed 69 times

3

In an application using the concepts of DDD I am in doubt about who could inject (dependencies) in a certain class, if there is any standard for such.

This is the following between the Application, Domain and Repository layers.

1) A Customer Service (Application layer) that needs to inject user, I should inject User Applicationservice and call it User Service(Domain) or inject User Service directly into Customer Applicationservice?

2) In Clienteservice(Domain) I should inject Usuarioservice and call it Usuariorepository or I could inject Usuariorepository directly into Clienteservice?

I am worried about cyclic reference if I am injecting same level classes.

But tbm I think I should not inject the Repository of another Entity, because many times the repository methods have a rule in the service that should be called earlier.

Someone has already had this doubt, as you normally treat it?

  • I work with all these concepts, and I can help you, but it would be interesting if you go into more detail about your question, post the classes of your example, even the injection module if possible.

1 answer

0

At the beginning of your text you ask "Who" could inject the dependency into a class.

Dependency injection is the role of dependency injection infrastructure.

In a dependency graph - "A" depends on "B" - which in turn "B" depends on "C" - which in turn "C" depends on "D" - which in turn "D" depends on "E" - which in turn "E" depends on "F"

All these elements must be injected by the infrastructure. Starting it creation of F, then E, then D, C, B and finally A.

Circular reference is a problem, avoid it is necessary.

Boundaries Contexts help limit this dependency to Boundary Context. You’re probably not following this concept of DDD.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.