종속성 주입을 구현하려고하는 Im Zend2 서비스 관리자를 사용합니다. PDO 인스턴스를 Service (Zend Db를 사용하지 않음)에 삽입하고 싶습니다.Zend2 서비스 할 종속성 주입 공장
임 여기 자습서 다음 https://framework.zend.com/manual/2.4/en/in-depth-guide/services-and-servicemanager.html
내가 다른 서비스를위한 작업이 있지만이 오류 점점 PDO 인스턴스 메신저를 주입 할 때 :이 관련 될 것으로 보인다 튜토리얼에서
Catchable fatal error: Argument 1 passed to Application\Service\DataService::__construct() must be an instance of Application\Service\DbConnectorService, none given, called in /srv/www/shared-apps/approot/apps-dev/ktrist/SBSDash/vendor/zendframework/zendframework/library/Zend/ServiceManager/ServiceManager.php on line 1077 and defined in /srv/www/shared-apps/approot/apps-dev/ktrist/SBSDash/module/Application/src/Application/Service/DataService.php on line 24
을 module.config의 내 호출 가능 항목에 추가하십시오. 그러나 문제가 무엇인지 해결할 수는 없습니다.
모든 조언을 주시면 감사하겠습니다.
DataService의 :
class DataService {
protected $dbConnectorService;
public function __construct(DbConnectorService $dbConnectorService) {
$this->dbConnectorService = $dbConnectorService;
}
......
DataServiceFactory :
namespace Application\Factory;
use Application\Service\DataService;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
class DataServiceFactory implements FactoryInterface {
function createService(ServiceLocatorInterface $serviceLocator) {
$realServiceLocator = $serviceLocator->getServiceLocator();
$dbService = $realServiceLocator->get('Application\Service\DbConnectorService');
return new DataService($dbService);
}
}
Module.Config : 여기
내 코드입니다 당신은 서비스를 만들려고'controllers' => array(
'factories' => array(
'Application\Controller\Index' => 'Application\Factory\IndexControllerFactory',
'Application\Service\DataService' => 'Application\Factory\DataServiceFactory',
)
),
'service_manager' => array(
'invokables' => array(
'Application\Service\DataServiceInterface' => 'Application\Service\DataService',
'Application\Service\DbConnectorService' => 'Application\Service\DbConnectorService',
)
),
'factory'가'controller' 배열에 있는지 확인 하시겠습니까? 그것은'service_manager'에 있어야합니다. – akond