In my module config file, I have these lines that loads libraries and models into ServiceManager so that I can retrieve them in Controllers. You can see all my models require same dependency. May I ask, how can I inject them without these repetitive blocks of code? This looks wrong to me but I do not know how an I run the same lines of code for different libraries. Or should I be using factories at all? Thank you!
'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; }, ), ),