We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Service not registered in the application container

Good afternoon, I try to build my first multi-module app using phalcon, but when I run my app only this message appear "0 - Service 'IntranetRH\Front\Module' was not found in the dependency injection container". My bootstrap file looks like this.

use Phalcon\DI\FactoryDefault;

 || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../apps'));


try {
 $di = new FactoryDefault();
    include __DIR__ . "/../apps/config/router.php";
    include __DIR__ . "/../apps/config/session.php";
    include __DIR__ . "/../apps/config/url.php";

$application = new \Phalcon\Mvc\Application($di);


            'front'  => array(
                'className' => 'IntranetRH\Front\Module',
                'path'      => '../apps/front/Module.php'


    echo $application->handle()->getContent();

        } catch (\Exception $e) {
echo $e->getCode() . ' - ' . $e->getMessage();

Module file :

use Phalcon\Loader,
Phalcon\Events\Manager as EventsManager;

class Module implements ModuleDefinitionInterface
 public function registerAutoloaders()
    $loader = new Loader();
            'IntranetRH\Front\Controllers' => '../apps/front/controllers/',
            'IntranetRH\Front\Models'      => '../apps/front/models/'

public function registerServices($di)
    //Registering a dispatcher
    $di->set('dispatcher', function() {
        $dispatcher = new Dispatcher();
         $eventsManager = new EventsManager();

        //Attach a listener
        $eventsManager->attach("dispatch:beforeDispatchLoop", function($event, $dispatcher) {

            $keyParams = array();
            $params = $dispatcher->getParams();

            //Use odd parameters as keys and even as values
            foreach ($params as $number => $value) {
                if ($number & 1) {
                    $keyParams[$params[$number - 1]] = $value;

            //Override parameters

        return $dispatcher;

    //Registering the view component
    $di->set('view', function() {
        $view = new View();

        ".twig" => function($view, $di) {
        * Setting up volt
        $volt = new \Phalcon\Mvc\View\Engine\Volt($view, $di);

            "compiledPath" => "../volt/index/",
            "compiledExtension" => ".php",
            'compiledSeparator' => '%%',
            'stat'              =>  1,
            'compileAlways' => true

        $compiler = $volt->getCompiler();
            //This binds the function name 'noformat' in Volt to the PHP function 'round'
            $compiler->addFunction('number_format', 'number_format');
            $compiler->addFunction('empty', 'empty');
            $compiler->addFunction('isset', 'isset');                
            $compiler->addFunction('utf8_encode', 'utf8_encode');
            $compiler->addFunction('utf8_decode', 'utf8_decode');

        return $volt;

        return $view;


Not entirely sure but it looks like your module file needs

    namespace IntranetRH\Front;
    # your code

at the beginning.

edited May '15

Thanx Andy, I added \Module to my namespace this is why it doesn't work :)