mercredi 7 juin 2017

Should I inject "child" dependencies into my client?

I have two services: service A and service B.

Service A depends on service B, therefore I inject service B into service A.

Now I need to use service A in my controller. I just need to call a method in service A, not in service B.

What is the best practice in dependency injection?

Should I just inject service A into my controller, because I only need to call a method in service A and not in service B?

Or should I inject both service A and service B into my controller, because I need to be explicit and advertise all the dependencies of my controller?

Aucun commentaire:

Enregistrer un commentaire