# Cannot inject "Client" in the Function signature of my Controller

**URL:** <https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953>\
**Category:** Programming (EN)\
**Created:** [19. Oktober 2021 um 06:13 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953 "2021-10-19T06:13:08Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)\
**Post date:** [19. Oktober 2021 um 06:13 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/1 "2021-10-19T06:13:09Z")

</div>

Good morning everybody.

I am trying to get a module inside my app up and running, but when I inject „Client“ in the controller function signature, I get the error: Cannot autowire argument $client.

An action button is working fine. There its possible to inject „Client“ and „Event“ without any problems.

module declaration inside of my manifest.xml

```auto
<module name="productExport"
		source="http://192.168.79.135/productExport">
	<label>Product Export</label>
	<label lang="de-DE">Produkt Export</label>
</module>

```

and the controller (nothing special):

```auto
/**
 * @Route("/productExport", name="productExport", methods={"GET"})
 */
public function productExport(Client $client): Response
{
	return $this->render('Product/product.export.html.twig', [
		'test' => bin2hex(random_bytes(16))
	]);
}

```

If I remove „Client“, the contents of the template is shown. I am totally desperate and have no clue how to solve this issue.

I Appreciate any kind of help.

Danny

---

<div class="post-metadata">

**Author:** ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)\
**Post date:** [19. Oktober 2021 um 06:48 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/2 "2021-10-19T06:48:52Z")

</div>

Guessing based on your obvious use domain (Export) you probably want to inject a service you use for authentication against the API, which one exactly is impossible to tell (Shopware\Core\Framework\Store\Services\StoreClient maybe? Check your PSR-4 records).  
In order to properly access the desired service, you have to do a proper DI with the services.xml syntax `(<argument type="service" id="shopware.store_client"/>)` and the actual injection into the controller (private var and assigning the injected service to an attribute of $this).  
„If I remove „Client“, the contents of the template is shown. I am totally desperate and have no clue how to solve this issue.“ Well… That’s because Symfony does its job concerning the render() method.

---

<div class="post-metadata">

**Author:** ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)\
**Post date:** [19. Oktober 2021 um 07:21 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/3 "2021-10-19T07:21:16Z")

</div>

Hi Jonas,

thanks for your response. I forgot to mention, that I am trying to implement an App and not an Extension.

Danny

---

<div class="post-metadata">

**Author:** ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)\
**Post date:** [19. Oktober 2021 um 07:29 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/4 "2021-10-19T07:29:13Z")

</div>

An app is an extension, just not a plugin.  
So which „Client“ do you inject now? That’s still the first issue to solve.

---

<div class="post-metadata">

**Author:** ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)\
**Post date:** [19. Oktober 2021 um 07:30 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/5 "2021-10-19T07:30:52Z")

</div>

I am using the AppTemplate:  
use App\SwagAppsystem\Client;

---

<div class="post-metadata">

**Author:** ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)\
**Post date:** [19. Oktober 2021 um 07:35 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/6 "2021-10-19T07:35:00Z")

</div>

May you show some more code? Like if `use App\SwagAppsystem\Client;` is included etc.

---

<div class="post-metadata">

**Author:** ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)\
**Post date:** [19. Oktober 2021 um 07:38 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/7 "2021-10-19T07:38:17Z")

</div>

Sure. Here is the complete Controller:

```auto
<?php declare(strict_types=1);

namespace App\Controller;

use App\Repository\ShopRepository;
use App\SwagAppsystem\Client;
use App\SwagAppsystem\Event;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class WebHookController extends AbstractController
{
    /** @var ShopRepository $shopRepository */
    private $shopRepository;

    public function __construct(ShopRepository $shopRepository)
    {
        $this->shopRepository = $shopRepository;
    }

    /**
     * @Route("/productExport", name="productExport", methods={"GET"})
     */
    public function productExport(Client $client): Response
    {
        return $this->render('Product/product.export.html.twig', [
            'test' => bin2hex(random_bytes(16))
        ]);
    }
}

```

---

<div class="post-metadata">

**Author:** ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)\
**Post date:** [19. Oktober 2021 um 08:40 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/8 "2021-10-19T08:40:09Z")

</div>

Manifest.xml (and other potentially existing files) content please.

---

<div class="post-metadata">

**Author:** ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)\
**Post date:** [19. Oktober 2021 um 08:55 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/9 "2021-10-19T08:55:22Z")

</div>

Here is the complete xml:

```auto
<?xml version="1.0" encoding="UTF-8"?>
<manifest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/shopware/platform/master/src/Core/Framework/App/Manifest/Schema/manifest-1.0.xsd">
    <meta>
        <name>testApp</name>
        <label>Test App</label>
        <description>Test</description>
        <author>Test</author>        
        <version>1.0.0</version>
        <license>proprietary</license>
    </meta>
    <setup>
        <registrationUrl>http://192.168.79.135/registration</registrationUrl>
        <secret>c7cca700f03344a7354f9d3c320adb1c</secret>
    </setup>
    <webhooks>
        <webhook name="AppDeleted" url="http://192.168.79.135/applifecycle/deleted" event="app.deleted"/>
        <webhook name="AppInstalled" url="http://192.168.79.135/applifecycle/installed" event="app.installed"/>
    </webhooks>
    <admin>
        <module name="productExport"
		source="http://192.168.79.135/productExport">
			<label>Product Export</label>
			<label lang="de-DE">Produkt Export</label>
		</module>
        <action-button action="sendOrder" entity="order" view="list" url="http://192.168.79.135/sendOrder">
            <label>Send selected Orders</label>
        </action-button>
    </admin>
</manifest>

```

---

<div class="post-metadata">

**Author:** ![jonas.joachim](https://avatars.discourse-cdn.com/v4/letter/j/e95f7d/32.png) [@jonas.joachim](https://forum.shopware.com/u/jonas.joachim)\
**Post date:** [19. Oktober 2021 um 09:12 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/10 "2021-10-19T09:12:54Z")

</div>

1. Controllers used in Apps have App\Controller as namespace and don’t inherit from AbstractController.
2. You can’t DI inject the shopRepository here in that fashion, because you don’t invoke it in service.xml/DI-container.

You put concepts together which don’t get along with each other, check this out for the start: [GitHub - shopwareLabs/AppExample](https://github.com/shopwareLabs/AppExample)

---

<div class="post-metadata">

**Author:** ![DannyDan](https://avatars.discourse-cdn.com/v4/letter/d/c2a13f/32.png) [@DannyDan](https://forum.shopware.com/u/DannyDan)\
**Post date:** [19. Oktober 2021 um 10:00 UTC](https://forum.shopware.com/t/cannot-inject-client-in-the-function-signature-of-my-controller/90953/11 "2021-10-19T10:00:31Z")

</div>

So, actually there is no need to inject the „Client“. In a module you just can get the shopdata from the request query. 🙂
