找不到Symfony 4订阅的服务注入

时间:2018-11-24 11:21:07

标签: symfony

方法getSubscribedServices似乎没有注入我的依赖关系。当我尝试将其与本地别名registry一起使用时,它表示未找到该服务;有人会知道我在想什么吗?

class UserService implements ServiceSubscriberInterface
{

protected $container;
protected $session;

public function __construct(ContainerInterface $container)
{
    $this->container = $container;
    $this->session = new Session();
}

public static function getSubscribedServices()
{
    return [
        'registry' => ManagerRegistry::class
    ];
}

呼叫$this->container->get('registry')失败,并显示错误消息

You have requested a non-existent service "registry". 

服务

App\Controller\userMgmt\UserService:
    lazy: true

usermgmt:
    alias: App\Controller\userMgmt\UserService
    public: true

堆栈跟踪

     Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
You have requested a non-existent service "Symfony\Bridge\Doctrine\ManagerRegistry".

at vendor/symfony/dependency-injection/Container.php:274
at Symfony\Component\DependencyInjection\Container->make('Symfony\\Bridge\\Doctrine\\ManagerRegistry', 1)
 (vendor/symfony/dependency-injection/Container.php:222)
at Symfony\Component\DependencyInjection\Container->get('Symfony\\Bridge\\Doctrine\\ManagerRegistry')
 (src/Controller/userMgmt/UserService.php:52)
at App\Controller\userMgmt\UserService->getPrivileges()
 (var/cache/dev/ContainerVwU8dOz/UserService_3c10c57.php:40)
at UserService_3c10c57->getPrivileges()
 (src/Controller/userMgmt/UserMgmtController.php:81)
at App\Controller\userMgmt\UserMgmtController->userLogin(object(Request), object(UserRepository))
 (vendor/symfony/http-kernel/HttpKernel.php:149)
at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
 (vendor/symfony/http-kernel/HttpKernel.php:66)
at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
 (vendor/symfony/http-kernel/Kernel.php:188)
at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
 (public/index.php:37)

0 个答案:

没有答案