Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
606 views
in Technique[技术] by (71.8m points)

symfony4 - 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 SymfonyContractsHttpClientHttpClientInterface;


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="SwagMasterBundleServiceProductManager" autowire="true" autoconfigure="true">
    <argument id="SymfonyContractsHttpClientHttpClientInterface" type="service" key="$httpClient"></argument>
</service>

But I am getting error:

The service "SwagMasterBundleServiceProductManager" has a dependency on a non-existent service "SymfonyContractsHttpClientHttpClientInterface".

Can anybody help me what I have done wrong here ?

Thank You.

question from:https://stackoverflow.com/questions/65843687/arguments-passed-to-the-services-giving-dependency-non-existence-service-error-i

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...