Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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é



11.1k
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!