在我的模块配置文件中,我有这些行将库和模型加载到 ServiceManager 中,以便我可以在控制器中检索它们。你可以看到我所有的模型都需要相同的依赖。请问,如果没有这些重复的代码块,我怎样才能注入它们呢?这在我看来是错误的,但我不知道如何为不同的库运行相同的代码行。还是我应该使用工厂?谢谢!
'service_manager' => array(
'abstract_factories' => array(
'Zend\Cache\Service\StorageCacheAbstractServiceFactory',
'Zend\Log\LoggerAbstractServiceFactory',
),
'aliases' => array(
'translator' => 'MvcTranslator',
),
'factories' => array(
// Models
'Application\Model\Photo' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Photo($coreLibrary, $io);
return $class;
},
'Application\Model\Album' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Album($coreLibrary, $io);
return $class;
},
'Application\Model\Tag' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Tag($coreLibrary, $io);
return $class;
},
'Application\Model\User' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\User($coreLibrary, $io);
return $class;
},
'Application\Model\Message' => function($serviceLocator) {
$coreLibrary = $serviceLocator->get('Project\CoreLibrary');
$io = $serviceLocator->get('Project\IO');
$class = new Application\Model\Message($coreLibrary, $io);
return $class;
},
),
),