Arguments passed to the services giving dependency non-existence service error in shopware 6

I have to use HttpClientInterface at my service page. So I defined as following:

use Symfony\Contracts\HttpClient\HttpClientInterface;


public function __construct(HttpClientInterface $httpClient)
    {
        $this->httpClient = $httpClient;
    }

In my services.xml file I have also trying passing the argument and also set autowiring

<!-- SERVICES -->
<service id="SwagMasterBundle\Service\ProductManager" autowire="true" autoconfigure="true">
    <argument id="Symfony\Contracts\HttpClient\HttpClientInterface" type="service" key="$httpClient"></argument>
</service>

But I am getting error:

The service "SwagMasterBundle\Service\ProductManager" has a dependency on a non-existent service "Symfony\Contracts\HttpClient\HttpClientInterface".

Can anybody help me what I have done wrong here ?

Thank You.

1 answer

  • answered 2021-01-22 11:30 alpham8

    You can't expect an interface, since an interface needs to be implemented from a concrete class. So, in your case you need an concrete object - Symfony services are simple objects.

    Please refer to object orientated programming basics first.

    Edit: Also autowiring and defining the given services doesn't make sense. Let the framework determine the needed object or do it yourself, but chose one option, not both at a time.