title: Zend2 Dependency injection factory to service
body: <p>Im trying to implement Dependency injection Using the Zend2 service manager. I want to inject a PDO instance into Service (Im not using the Zend Db).</p>
  
  <p>Im following the tutorial here: <a href="https://framework.zend.com/manual/2.4/en/in-depth-guide/services-and-servicemanager.html" rel="nofollow noreferrer">https://framework.zend.com/manual/2.4/en/in-depth-guide/services-and-servicemanager.html</a></p>
  
  <p>I have it working for another service, but the when injecting the PDO instance Im getting this error:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>From the tutorial this seems to be related to my invokeables in the module.config. But I cannot work out what the issue is.</p>
  
  <p>Any advice is appreciated.</p>
  
  <p>Here is my code:</p>
  
  <p>DataService:</p>
  
  <pre><code>class DataService {
  protected $dbConnectorService;
  
  public function __construct(DbConnectorService $dbConnectorService) {
      $this-&gt;dbConnectorService = $dbConnectorService;
  }
  ......
  </code></pre>
  
  <p>DataServiceFactory:</p>
  
  <pre><code>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-&gt;getServiceLocator();
      $dbService = $realServiceLocator-&gt;get('Application\Service\DbConnectorService');
  
      return new DataService($dbService);
  }
  
  }
  </code></pre>
  
  <p>Module.Config:</p>
  
  <pre><code>'controllers' =&gt; array(
  'factories' =&gt; array(
          'Application\Controller\Index' =&gt; 'Application\Factory\IndexControllerFactory',
          'Application\Service\DataService' =&gt; 'Application\Factory\DataServiceFactory',
      )
  ),
      'service_manager' =&gt; array(
      'invokables' =&gt; array(
          'Application\Service\DataServiceInterface' =&gt; 'Application\Service\DataService',
          'Application\Service\DbConnectorService' =&gt; 'Application\Service\DbConnectorService',
      )
  ),
  </code></pre>