New in Symfony 3.3: Deprecated the autowiring types
Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
One of the most common issues when using autowiring in Symfony applications is having two or more services implementing the same interface. The autowiring subsystem cannot guess which one to use in each case and you end up seeing this error message:
[Symfony\Component\DependencyInjection\Exception\RuntimeException] Unable to autowire argument of type "..." for the service "...".
This problem is solved using the
autowiring_types option to define which is
the default implementation to use:
1 2 3 4 5 6 7
# app/config/services.yml services: annotations.reader: class: Doctrine\Common\Annotations\AnnotationReader autowiring-type: Doctrine\Common\Annotations\Reader public: false # ...
In Symfony 3.3 we decided to simplify this feature and autowiring-types are now deprecated. Instead, you must use simple service aliases:
1 2 3 4 5 6 7 8 9
# app/config/services.yml services: annotations.reader: class: Doctrine\Common\Annotations\AnnotationReader public: false Doctrine\Common\Annotations\Reader: alias: annotations.reader public: false
It's recommended to create the new service aliases as private because you don't need them to be available in the compiled container.
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.