Search code examples
phpsymfonydependency-injectionyamlautowired

Cannot autowire vendor service: has no type-hint, you should configure its value explicitly


In my Symfony 6 app, I am trying to use dependency injection within my service.yaml file to bind some arguments but getting an error:

Cannot autowire service "Microsoft\BingAds\Auth\ServiceClient": argument "$serviceClientType" of method "__construct()" has no type-hint, you should configure its value explicitly.

And in the YAML file:

Microsoft\BingAds\Auth\ServiceClient:
    autowire: true

The problem with it is that it is a part of the vendor library package so I can not edit it.

Maybe it is not necessary but the ServiceClient class constructor looks something like this:

public function __construct($serviceClientType, $authorizationData, $apiEnvironment, $options = array())
    {
        ...
    }

Can someone help with how to surpass this error?

Thanks


Solution

  • It says you that autowiring doesn't work because arguments are not type-hinted. So set it explicitly in service.yaml:

    Microsoft\BingAds\Auth\ServiceClient:
        arguments:
            $serviceClientType: YOUR_VALUE_HERE
            $authorizationData: YOUR_VALUE_HERE
            $apiEnvironment: YOUR_VALUE_HERE