Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Shameer C:
Automatic construction injection in Slim 3
Oct 20, 2015 @ 16:09:38

Shameer C has a post to his site showing you how to automatically inject values in constructors on Slim 3 based applications. This makes use of the inheritance of constructor parameter functionality the Aura.DI container makes available.

In the previous blog post we have discussed how to replace the default Pimple Container with Aura.DI in Slim framework 3. Aura.DI gives us more flexibility in terms of managing dependencies. We saw one most useful feature in Aura.DI, Inheritance of constructor parameters, that will help us to avoid repeating common parameters for Controllers and Models. In this article we will see another advantage of the same feature.

He gives an example of how, with the default DI container in Slim (Pimple) you have to make a new instance of a class manually each time you need it. He talks about how Slim 3 internally resolves controller classes (using a CallableResolver) and a small change that can be made to prevent you from needed to define every constructor into the DI container and allow for more dynamic handling.

tagged: automatic injection constructor callableresolver slim3 tutorial auradi dependencyinjection

Link: http://blog.shameerc.com/2015/10/automatic-construction-injection-in-slim-3


Trending Topics: