I am trying to access a DB using the EntityManager in my event listener but I got the following error and I do not know where the problem is.
ServiceCircularReferenceException in PhpDumper.php line 508: Circular reference detected for service "doctrine.dbal.default_connection", path: "doctrine.dbal.default_connection".
services.yml
testListener:
class: 'AppBundle\Event\MyListener'
arguments: ['@mailer','@doctrine.orm.entity_manager']
tags:
- { name: doctrine.event_listener, event: postPersist }
MyListener
use AppBundle\Service\Mailer;
use Doctrine\ORM\EntityManager;
class MyListener
{
private $mailer;
protected $em;
function __construct(Mailer $mailer ,EntityManager $em)
{
$this->mailer = $mailer;
$this->em = $em;
}
public function postPersist(LifecycleEventArgs $args){//.....}
}