Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

3
  • Quite. My implementation (currently works) is similar. I register a db service and define a get($class) method in it. Then I call the service's get method in controller with the model class I need. The service factory creates an instance and injects the dependencies I specify. I'm not sure this is proper DI, but I guess it will suffice. Commented Nov 16, 2012 at 9:29
  • @Sam Do you have any solution for cases with circular dependencies? For example in your answer, what if Doctrine\ORM\EntityManager required an instance of SomeService? There would be a never ending recursive loop. Commented Dec 2, 2016 at 20:15
  • @binnyb that sounds like bad design :) There's not really a solution to that other than to refactor the dependencies into stuff that makes sense. Proper examamples may be required to aid you with this. Commented Dec 6, 2016 at 10:51