Developing software in the Real World

Dependency injection in Slim framework 2

Slim framework comes with a Dependency Injection container called Set. The basics The DIC is accessed via the container property of $app. To set, you use the set() method:

If you need a given resource to be shared, then use the singleton method:

And then to retrieve from the container, there are multiple ways to do it:

The shortcut version ($app->foobar) only works if the key is a valid PHP variable name.… continue reading.