Q:

Cannot attach Events in module init()-method

I read about some of the best practices for ZF2. There, it was explained to attach the events from MVC in the init()-Method of the module's Module class:
class Module {

  public function getAutoloaderConfig()  {
      return array(
        'Zend\Loader\ClassMapAutoloader' => array(
          __DIR__ . '/autoload_classmap.php',
        ),
      );
    }

    public function init(ModuleManager $moduleManager) {
      echo 'init<br>';
      $em = $moduleManager->getEventManager();
      $em->attach(MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'));
      $em->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute'));
    }

    public function onDispatch(MvcEvent $e){
      echo 'onDispatch<br>';
    }
    ...

It results in getting no error, nice. But the event is not caught...
Any ideas? I tried the SharedManager too, but it only worked for the EVENT_DISPATCH ...

A:

See http://akrabat.com/zend-framework-2/module-specific-bootstrapping-in-zf2/
Only found this solution: attach listeners in onBootstrap()-Method in the Module.php class:
...
public function onBootstrap(MvcEvent $e){
 echo 'onBootstrap<br>';
 $em =  $e->getApplication()->getEventManager();
 $em->attach(MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'));
 $em->attach(MvcEvent::EVENT_ROUTE, array($this, 'onRoute'));
}

...

