ZF2-284: DI reused "shared" parameters for dependencies, which crates unexpected problems

Description

I ran into a situation in which DI is attempting to inject the wrong options parameter to an incorrect 'dependant' class.

see: http://zend-framework-community.634137.n4.nabble.com/…

but it boils down to DI trying to inject 'my-service-configuration' as options to Filesystem which is an CacheAdapter instantiated by the CacheFactory::factory


'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */ 
                'parameters' => array( 
                    'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */ 
                    'logger'       => 'my-logger', /* is a Logger instance */ 
                    'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */ 
                ), 
            ), 

relevant module.conf.php at https://gist.github.com/2568952

backtrace


#0 .../vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions)) 
#1 .../vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions)) 
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions)) 
#3 .../vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array) 
#4 .../vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'my-cache-ada...', false) 
#5 .../vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array) 
#6 .../vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array) 
#7 .../vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false) 
#8 .../vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false) 
#9 .../vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array) 
#10 .../module/MyService/Module.php(46): Zend\Di\Di->get('my-service') 

Comments

Changing My\Service constructor to consume $serviceOptions is has been confirmed to avoid this problem.

This issue has been closed on Jira and moved to GitHub for issue tracking. To continue following the resolution of this issues, please visit: https://github.com/zendframework/zf2/issues/2475