我已经创建了自己的服务,我需要注入doctrine EntityManager,但是我没有看到__construct()在我的服务上调用它,并且注入不起作用.
这是代码和配置:
<?php
namespace Test\CommonBundle\Services;
use Doctrine\ORM\EntityManager;
class UserService {
/**
*
* @var EntityManager
*/
protected $em;
public function __constructor(EntityManager $entityManager)
{
var_dump($entityManager);
exit(); // I've never saw it happen, looks like constructor never called
$this->em = $entityManager;
}
public function getUser($userId){
var_dump($this->em ); // outputs null
}
}
Run Code Online (Sandbox Code Playgroud)
这是services.yml我的捆绑
services:
test.common.userservice:
class: Test\CommonBundle\Services\UserService
arguments:
entityManager: "@doctrine.orm.entity_manager"
Run Code Online (Sandbox Code Playgroud)
我已经config.yml在我的应用程序中导入了.yml
imports:
# a few lines skipped, not relevant here, i think
- { resource: …Run Code Online (Sandbox Code Playgroud)