title: ZF2 events for multiple modules
body: <p>Currently I have an ZF2 application configured with the single module "application". I bootstrap the application an attach an event this way:</p>
  
  <pre><code>namespace Application;
  
  use Zend\Mvc\ModuleRouteListener;
  use Zend\Mvc\MvcEvent;
  
  class Module
  {
      public function onBootstrap( MvcEvent $e)
      {
          $eventManager        = $e-&gt;getApplication()-&gt;getEventManager();
          $moduleRouteListener = new ModuleRouteListener();
          $moduleRouteListener-&gt;attach( $eventManager);
  
          $this-&gt;initTracking( $e);
      }
  
      /**
       * Initialises user tracking check
       * @param MvcEvent $e
       */
      public function initTracking( MvcEvent $e) 
      {
          $eventManager = $e-&gt;getApplication()-&gt;getEventManager();
          $eventManager-&gt;attach( 'dispatch', function( $e){ 
              $objTracking = new \Application\Event\Tracking( $e);
          }, 200);
      }
  }
  </code></pre>
  
  <p>Now I need to create a new module "api", which should process only urls starting domain.com/api (I configure the router in "api" module config file to handle only such urls).
  I bootstrap the "api" module the same way as "application" module, and I attach a dedicated event:</p>
  
  <pre><code>namespace Api;
  
  use Zend\Mvc\ModuleRouteListener;
  use Zend\Mvc\MvcEvent;
  
  class Module
  {
      public function onBootstrap( MvcEvent $e)
      {
          $eventManager        = $e-&gt;getApplication()-&gt;getEventManager();
          $moduleRouteListener = new ModuleRouteListener();
          $moduleRouteListener-&gt;attach( $eventManager);
  
          $this-&gt;initLogging( $e);
      }
  
      /**
       * Initialises loggging
       * @param MvcEvent $e
       */
      public function initLogging( MvcEvent $e) 
      {
          $eventManager = $e-&gt;getApplication()-&gt;getEventManager();
          $eventManager-&gt;attach( 'dispatch', function( $e){ 
              $objLogger = new \Application\Event\Logging( $e);
          }, 200);
      }
  }
  </code></pre>
  
  <p>What happens is that when I call domain.com/application - both modules are being initialised and events from both modules are being triggered. I need events to be triggered depending on the application which is dispatching the action.</p>
  
  <p>How can I achieve that?</p>