thephpleague / container

Small but powerful dependency injection container

Home Page:http://container.thephpleague.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alias (Name of alias) is not being managed by the container

SH1R3F opened this issue · comments

Hello I got this issue when I used League\Container

I added these lines of code into my AppServiceProvider

    public $provides = ['testing'];

    public function register()
    {
        $container = $this->getContainer();

        $container->share('testing', function(){
            return 'it works';
        });
    }

and this line into my container file

use League\Container\Container;

$container = new Container;

var_dump($container->get('testing'));

and when I run the code on my browser I always get this error:
Fatal error: Uncaught League\Container\Exception\NotFoundException: Alias (testing) is not being managed by the container or delegates in /srv/http/myframework/vendor/league/container/src/Container.php:179 Stack trace: #0 /srv/http/myframework/bootstrap/container.php(7): League\Container\Container->get('testing') #1 /srv/http/myframework/bootstrap/app.php(20): require_once('/srv/http/myfra...') #2 /srv/http/myframework/public/index.php(3): require_once('/srv/http/myfra...') #3 {main} thrown in /srv/http/myframework/vendor/league/container/src/Container.php on line 179

What is the problem and how can I fix it?

I solved it. I forgot to call my $container->addServiceProvider(my provider);
into my container file