title: ZF2 ServiceManager - adding new module
body: <p>I started learning ZF2 but have a problem with ServiceManager.</p>
  
  <p>I tried to add new Module "Menu" to ServiceManager.</p>
  
  <p>In my application/config/module.config.php added this code:</p>
  
  <pre><code>'service_manager' =&gt; array(
          'factories' =&gt; array(
              'translator' =&gt; 'Zend\I18n\Translator\TranslatorServiceFactory',
              'menu'       =&gt; 'Application\Menu\MenuServiceFactory',
          ),
      ),
  
      'menu' =&gt; array(
  
      ),
  </code></pre>
  
  <p>Application\src\Menu\MenuServiceFactory.php:</p>
  
  <pre><code>namespace Application\Menu;
  
  use Zend\ServiceManager\FactoryInterface;
  use Zend\ServiceManager\ServiceLocatorInterface;
  
  /**
   * Menu
   */
  class MenuServiceFactory implements FactoryInterface
  {
      public function createService(ServiceLocatorInterface $serviceLocator)
      {
          // Configure the Menu
          $config = $serviceLocator-&gt;get('Config');
          $menuConfig = isset($config['menu']) ? $config['menu'] : array();
          $menu = Menu::factory($menuConfig);
          return $menu;
      }
  }
  </code></pre>
  
  <p>Application\src\Menu\Menu.php:</p>
  
  <pre><code>namespace Application\Menu;
  
  
  /**
   * Menu
   */
  class Menu
  {
  
      /**
       * Instantiate a menu
       *
       * @param  array $options
       * @return Menu
       */
      public static function factory($options)
      {
  
          $menu = 'test';
          return $menu;
      }
  
  
  }
  </code></pre>
  
  <p>If I tried add this "$menu = $this->getServiceLocator()->get('menu');" I received:</p>
  
  <pre><code>    Zend\ServiceManager\Exception\ServiceNotCreatedException
  
  File:
  E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:871
  Message:
  While attempting to create menu(alias: menu) an invalid factory was registered for this instance type.
  Stack trace:
  #0 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(494): Zend\ServiceManager\ServiceManager-&gt;createFromFactory('menu', 'menu')
  #1 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(441): Zend\ServiceManager\ServiceManager-&gt;create(Array)
  #2 E:\Projects\zf2\module\AdminSettings\src\AdminSettings\Controller\SettingsController.php(193): Zend\ServiceManager\ServiceManager-&gt;get('menu')
  #3 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): AdminSettings\Controller\SettingsController-&gt;logoAction()
  #4 [internal function]: Zend\Mvc\Controller\AbstractActionController-&gt;onDispatch(Object(Zend\Mvc\MvcEvent))
  #5 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(472): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
  #6 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager-&gt;triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #7 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager-&gt;trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #8 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController-&gt;dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
  #9 [internal function]: Zend\Mvc\DispatchListener-&gt;onDispatch(Object(Zend\Mvc\MvcEvent))
  #10 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(472): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
  #11 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager-&gt;triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #12 E:\Projects\zf2\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(294): Zend\EventManager\EventManager-&gt;trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
  #13 E:\Projects\zf2\public\index.php(13): Zend\Mvc\Application-&gt;run()
  #14 {main}
  </code></pre>
  
  <p>Does anyone have an idea to resolve this error?</p>