In my ZF2 application, I use Zend\Di\Di
to create all my class instances. The DI definitions are scanned using Zend\Di\Definition\CompilerDefinition
and cached using APC. This avoids scanning the classes at runtime using slow reflection. If there is an exception during instance creation (because of outdated DI definitions), the code is rescanned, the definitions are cached, and the instance is created again.
This is very convenient during development, since no factory methods/closures have to be written or changed for new classes or changed constructors. My constructors follow a certain convention (only type-hinted arguments and a singe $params array) to ensure that dependency injection works without specifying additional constructor params.
Up till now, this performs nicely, avoids bugs (no outdated factory methods), and speeds up development. However, the scanned definitions are currently 1.8MB (serialized array) in APC, and growing. Since they have to be loaded from cache upon every request, I fear that memory will be exhausted if there are too many requests in a short time. I have no load testing setup to simulate this, though.
I'm aware that the recommended way is to use Zend\ServiceManager and write factory closures for every class, instead of using Zend\Di\Di. But I imagine this is a lot of work and quite annoying during development.
Do you recommend refactoring to Zend\ServiceManager in this situation?