I am trying to inject cache to a module using module.config.php with no luck. My module.config.php looks like this
return array(
'di' => array(
'instance' => array(
'AssetLoader\Module' => array(
'parameters' => array(
'cache' => 'Zend\Cache\Storage\Adapter\Filesystem',
),
),
),
),
);
and in my Module.php
public function setCache(\Zend\Cache\Storage\Adapter\Filesystem $cache)
{
die(__FUNCTION__);
$this->cache = $cache;
}
But nothing happens. I expect script to die but for some reason this function is never executed. I am sure I am doing something wrong but can someone explain how to inject a cache (or any other object in that matter) to the module?
This question is answered on Zend mailing list now.
See here
Matthew pointed out that Module classes weren’t pulled out from locator, so you can’t use DI to inject resources to the modules. See the link to see how it’s done.