0

I have a service where I inject too many services (10-15) in Symfony framework (I don't think so framework matter).

  • I know it will have an impact on performance but want to answer in detail how ???
  • What happens behind the scene, means memory perspective. ???
  • See if help this https://stackoverflow.com/questions/26679524/many-dependencies-in-service – Kolovos Konstantinos Dec 04 '20 at 14:39
  • 1
    Are you saying you actually ran into a problem or just wondering if you will? Typically the only problem with a class having say 15 dependencies is that the class is doing too much and needs to be redesigned. – Cerad Dec 04 '20 at 16:32
  • Hi @Cerad thanks for the reply, Actually I need to improve the existing system they have too many dependencies, So I wanna know what's happen in the background (memory perspective). – Nauman Ilyas Dec 09 '20 at 13:45
  • You might want to use a profiler tool of some kind. Obviously the more dependencies the more memory but 15 objects is not very much in the grand scheme of things. If you are making thousands of these objects then yes, memory could start to be an issue. But the fact that some kind of dependency injection is being used is not going to impact memory usage in any significant fashion. – Cerad Dec 09 '20 at 14:15

1 Answers1

0

There are multiple service injection types and they all come with advantages/disadvantages. If you're talking about optional dependencies, setter injection could be an approach.

rnenciu
  • 368
  • 4
  • 13
  • Hi @rnenciu I appreciate your answer. I also see the documentation but there are some limited not more in-depth that I want. I'm using setter injection . – Nauman Ilyas Dec 10 '20 at 12:50