Compiled DI and Developer DI Are Sometimes Incompatible #6739
I have found that there are some cases where classes will be introspected by Reflection in the Developer mode, but will not be caught by the
As far as I know, this affects every version of Magento 2.0 and 2.1, but I was using 2.0.8 at the time. The environment is modern and following all best practices, and was replicated across a variety of environments.
Steps to reproduce
I'm not 100% sure what the correct thing to do here is. If we accept that the behaviour should at least be consistent, our options are to prevent the Developer DI from working with external classes (which I don't like), or to enhance the Compiled DI so that it works with external classes that are referred to through generated classes (I like this one more).
A compromise might be to document it well, or something.
For anyone stumbling across this issue, it can be fixed by adding an empty class to your module, and having it extend your external class. Tell Anton Kril that I found a use for inheritance.
If you generate a factory for this class in your module, it will find the parent constructor arguments without issue. You can add a preference into
The text was updated successfully, but these errors were encountered:
We made a fix in 2.2.0 for this case
but we still state that Compiler may not be able to resolve all dependencies on 3rd party classes. That’s why 3rd party classes should not be injected in the constructor of Magento classes, instead, they should be instantiated via new operator, preferably in adapters only.
Third party (3P) libs don't mean third party libraries that are actually registered with ComponentRegistrar as components of type "library," it means generic php libraries that are not special Magento application components. So this is about unregistered 3P libraries.