Reputation: 331
I wrote simple Service which is using EntityManagerInterface and it's working but when I try in similar way add UserInterface I get:
AutowiringFailedException Cannot autowire service "AppBundle\Service\Pricer": argument "$user" of method "__construct()" references interface "Symfony\Component\Security\Core\User\UserInterface" but no such service exists. It cannot be auto-registered because it is from a different root namespace.
My code is:
namespace AppBundle\Service;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\User\UserInterface;
class Pricer
{
private $em;
private $user;
public function __construct(EntityManagerInterface $em, UserInterface $user)
{
$this->em = $em;
$this->user = $user;
}
}
It's working when I have only EntityManagerInterface as argument (I can get Repository and make some find queries). Where is my mistake?
Upvotes: 1
Views: 2022
Reputation: 29912
Basically because Doctrine ORM has provided a default implementation for EntityManagerInterface
(that is EntityManager
, you can check it out here) whereas Symfony didn't with UserInterface
. The reason behind this is that UserInterface
is something that describes a contract/public api of a model entity, not a service so this won't suit the concept of service injection.
Upvotes: 6