public function build(array $config, ContainerInterface $container = null)
    {
        $dispatcher = new Dispatcher($container);
        foreach ((array) $config as $name => $listeners) {
            foreach ($listeners as $listener) {
                if (is_callable($listener)) {
                    $dispatcher->register($name, $listener);
                    continue;
                }

                $listener = $this->applyDefaults($listener);

                $dispatcher->register(
                    $name,
                    $this->buildDefinition($listener)
                );
            }
        }

        return $dispatcher;
    }