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: $app->container->set('foobar', function() { return new Foo\Bar(); } ); If you need a given resource to be shared, then use the singleton method: $app->container->singleton('foobar', function() { return new Foo\Bar(); } ); And th
![Dependency injection in Slim framework 2](https://cdn-ak-scissors.b.st-hatena.com/image/square/284c30ba242bfb25725914757566b78852b8df46/height=288;version=1;width=512/https%3A%2F%2Fakrabat.com%2Fwp-content%2Fuploads%2Fakrabat-header.jpeg)