Relying on service auto-registration error on ORM entity Relying on service auto-registration error on ORM entity symfony symfony

Relying on service auto-registration error on ORM entity


Do you have any Classes under Service-auto registration which use an Entity as constructor argument?

That's where your problem comes from.

You need to ask yourself if the concerning class really is a service or just a plain object of which you always create the instance yourself.

If it is not used as a service through the container you have 2 options:

You can exclude this class also through the glob pattern like for example

AppBundle\:    resource: '...'    # you can exclude directories or files    # but if a service is unused, it's removed anyway    exclude: '../../{Entity,PathToYourNotService}'

or you can set the following parameter in your config

parameters:    container.autowiring.strict_mode: true

with this option the container won't try to create a service class with arguments that are not available as services and you will get a decisive error. This is the default setting for sf4

A good example for a class that triggers exactly this error would be a custom event class that takes an entity as payload in the constructor:

namespace AppBundle\Event;use AppBundle\Entity\Item;use Symfony\Component\EventDispatcher\Event;class ItemUpdateEvent extends Event{    const NAME = 'item.update';    protected $item;    public function __construct(Item $item)    {        $this->item = $item;    }    public function getItem()    {        return $this->item;    }}

Now if this file isn't excluded specifically the container will try to auto register it as service. And because the Entity is excluded it can't autowire it. But in 3.4 there's this fallback which triggers this warning. Once the strict_mode is activated the event just won't be available as service and if you tried using it as one an error would rise.