$dbConfig = $config->database->toArray();
    $adapter = $dbConfig['adapter'];
    unset($dbConfig['adapter']);
    $class = 'Phalcon\\Db\\Adapter\\Pdo\\' . $adapter;
    return new $class($dbConfig);
});
/**
 * If the configuration specify the use of metadata adapter use it or use memory otherwise
 */
$di->setShared('modelsMetadata', function () {
    return new MetaDataAdapter();
});
$di->setShared('logger', function () use($config) {
    $formatter = new \Phalcon\Logger\Formatter\Line('%date% %type%  %message%');
    $logger = new \Phalcon\Logger\Adapter\File('../phalcon.log');
    $logger->setLogLevel(\Phalcon\Logger::DEBUG);
    $logger->setFormatter($formatter);
    return $logger;
});
/**
 * Start the session the first time some component request the session service
 */
$di->setShared('session', function () {
    $session = new Phalcon\Session\Adapter\Libmemcached(array('servers' => array(array('host' => 'localhost', 'port' => 11211, 'weight' => 1)), 'client' => array(Memcached::OPT_HASH => Memcached::HASH_MD5, Memcached::OPT_PREFIX_KEY => 'prefix.'), 'lifetime' => 3600, 'prefix' => 'my_'));
    $session->start();
    return $session;
});
$di->set('security', function () {
    $security = new \Phalcon\Security();
    $security->setWorkFactor(12);
    return $security;