Closed prostoroman closed 9 years ago
Yes, you can do that. It's known as Service Location and is considered by some to be an anti-pattern. See https://adamcod.es/2013/11/25/service-locator-vs-dependency-injection-container.html for a good explanation of the differences.
It does however work!
The main risks are related to the fact that you can now access anything that's in your container within the controller which can lead to scope creep and hidden dependencies in your controller. Testing is also harder as you now have to mock the container too.
Ok, I understand, thank you!
Hello, Dear Rob.
Thank you for great code!
Is it possible to put full DI container to HomeAction construct method?
slim3-skeleton/app/src/Action/HomeAction.php:
change to something like this:
In order to have access to full list of dependencies from class? Or it's a bad idea?
If I need a logger, view, flash, database mapper etc in one place.