aws-sdk-php-phalcon icon indicating copy to clipboard operation
aws-sdk-php-phalcon copied to clipboard

Service 'aws' wasn't found in the dependency injection container

Open kmichailg opened this issue 10 years ago • 0 comments

I have this code to register services:

services.php

$di = new FactoryDefault();
$di->set('dispatcher', function () use ($config) {
    $eventsManager = new EventsManager;
    $eventsManager->attach("application:boot", new AwsServiceProvider(array(
        'key'    => $config->s3->key,
        'secret' => $config->s3->secret,
        'region' => $config->s3->region,
    )));

    $dispatcher = new Dispatcher;
    $dispatcher->setEventsManager($eventsManager);

    return $dispatcher;
}

public/index.php

    /**
     * Load application services
     */
    require APP_PATH . 'app/config/services.php';

    $application = new Application($di);

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

But when I call this line of code from any controller:

$s3 = $this->getDI()->get('aws')->get('s3');

This is what's printed on the error log:

Service 'aws' wasn't found in the dependency injection container

#0 \app\controllers\AccountController.php(22): Phalcon\Di->get('aws')
#1 [internal function]: AccountController->indexAction()
#2 [internal function]: Phalcon\Dispatcher->dispatch()
#3 \public\index.php(46): Phalcon\Mvc\Application->handle()
#4 {main}

kmichailg avatar Jan 20 '16 09:01 kmichailg