JMSSerializerBundle icon indicating copy to clipboard operation
JMSSerializerBundle copied to clipboard

can't inject service in subscriber

Open hatem20 opened this issue 6 years ago • 1 comments

I am trying to create subscriber and use onPostSerialize method everything works fine until I needed to inject container in Subscriber's constructor

<service id="app.resources_config_serializer_subscriber.link_serialization_subscriber" class="AppBundle\Resources\config\serializer\Subscriber\LinkSerializationSubscriber" autowire="true" public="true">
            <tag name="jms_serializer.event_subscriber" />
            <argument type="service" id="service_container" />
</service>

I keep getting

Type error: Too few arguments to function AppBundle\\Resources\\config\\serializer\\Subscriber\\LinkSerializationSubscriber::__construct(), 0 passed in var/cache/dev/ContainerJhxxdml/getJmsSerializerService.php on line 27 and exactly 1 expected"

it seem like onPostSerialize is called twice because i could dump container but when i remove the dump statement, the error happens again.

    public function __construct(Container $container)
    {
        $this->container = $container;
    }

hatem20 avatar Jul 15 '19 21:07 hatem20

I think your issue is related to symfony auto wiring.... not to this bundle. Make sure autowring is well configured

goetas avatar Jul 16 '19 08:07 goetas