We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Injectables

Hi

Are there any drawbacks of extending your class with \Phalcon\Di\Injectable rather that implementing InjectionAwareInterface on your class?

As I see it extending with Injectable also gives you the eventmanager.

Regards André



16.4k
Accepted
answer

I haven't found one, its a great way to build a lib that talks directly with phalcon ;)

Injectable is just implemented InjectionAwareInterface class. You just have $this->di in your class, you dont have to do it on your own. It returns di using static Di::getDefault() method.

edited Jan '16

What I did, build a custom class /sharedService for a very specific task,

Class is defined as:

function __construct(\Phalcon\DiInterface $diInterface)

So at runtime, sharedService container is injecting $di variable from services.php scope, thus making my custom class aware of all the dependencies during invocation. Phalcon is doing a great job of using DI concept at first place!