Contents
- 1. The boundary: what's allowed in constructors?
- 2. Injectable objects: services and managers
- 3. Non-injectable objects: models and DataObjects
- 4. Why models must not be injected
- 5. Factory as the solution: auto-generated factories
- 6. Custom factories and factory methods
- 7. Shared vs. non-shared in di.xml
- 8. Proxy: lazy loading for expensive injectable objects
- 9. PHPStan: finding non-injectable violations
- 10. Conclusion: the golden rule of DI
One of the most common causes of bugs in Magento modules: a Model gets injected directly into a constructor. This is subtly wrong and causes unexpected side effects,