# Auf Klasse aus anderem Plugin in Console Comand zugreifen

**URL:** <https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885>\
**Category:** Programmierung\
**Created:** [28. August 2017 um 14:59 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885 "2017-08-28T14:59:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [28. August 2017 um 14:59 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/1 "2017-08-28T14:59:34Z")

</div>

Hi, ich habe in einem Plugin über&nbsp;$this-\>Application()-\>Loader()-\>registerNamespace() ein Helfer-Klasse registriert. Daraauf kann in innerhalb meines Controllers auch zugreifen.

&nbsp;

Jetzt habe ich ein &nbsp;2. Plugin bei dem ich ein COnsolen Command registriert habe. Innerhalb dieses Commandos kann ich aber nicht auf meine Klasse aus dem 1. Plugin zugreifen.&nbsp;

Steht der Namespace hier nicht zur Verfügung bzw. ist nicht bekannt?

Vielen Dank

&nbsp;

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)\
**Post date:** [29. August 2017 um 06:27 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/2 "2017-08-29T06:27:03Z")

</div>

Ich würde die Klasse einfach in den DI Container legen. Damit soltlest du ohne Probleme dran kommen.&nbsp;

Verwendest Du das neue Plugin System?

---

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [29. August 2017 um 08:34 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/3 "2017-08-29T08:34:54Z")

</div>

Die Klasse die ich verwenden möchte, stammt aus dem alten Plugin System. Ich möchte sie aber in einen Plugin im neuen System verwenden.&nbsp;

Wie kann ich die Klasse in den DI Container legen?

vielen Dank.&nbsp;

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)\
**Post date:** [29. August 2017 um 08:54 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/4 "2017-08-29T08:54:19Z")

</div>

Die Beschreibung [Plugin services](https://developers.shopware.com/developers-guide/services/#registering-the-service) sollte dir da weiterhelfen 🙂

---

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [29. August 2017 um 09:47 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/5 "2017-08-29T09:47:51Z")

</div>

hhmmm… &nbsp;das hat irgendwie nciht funktionier. ich habe jetzt in meiner 1. Plugin folgendes Event registriert:

```
$this->subscribeEvent(
            'Enlight_Bootstrap_InitResource_my_plugin_test.my_services',
            'onInitMyServices'
        );

/**
     * @return \Shopware\Test\MyServices
     */
    public function onInitMyServices()
    {
        return new \Shopware\Test\MyServices();
    }

```

&nbsp;

```
public function afterInit()
    {

        //register component
        $this->Application()->Loader()->registerNamespace(
            'Shopware\Test',
            $this->Path() . "Components/"
        );

    }

```

Wenn ich nun in meinem 2. Plugin folgendes aufrufe:&nbsp;

```
$test = Shopware()->Container()->get('my_plugin_test.my_services');

```

erhalte ich folgenden fehler:&nbsp;

[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException]&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

&nbsp; You have requested a non-existent service “my\_plugin\_test.my\_services”.

Kann ich irgendwo prüfen ob das Event “Enlight\_Bootstrap\_InitResource” korrekt registriert wurde?

&nbsp;

---

<div class="post-metadata">

**Author:** ![Thomas](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/thomas/32/8167_2.png) [@Thomas](https://forum.shopware.com/u/Thomas)\
**Post date:** [29. August 2017 um 09:51 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/6 "2017-08-29T09:51:09Z")

</div>

Kannst du mir beide Plugins bitte einmal schicken? Dann schaue ich mir gerne an.

---

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [29. August 2017 um 10:23 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/7 "2017-08-29T10:23:04Z")

</div>

> [@Thomas schrieb:](https://forum.shopware.com/profile/16897/Thomas "Thomas")
> 
> Kannst du mir beide Plugins bitte einmal schicken? Dann schaue ich mir gerne an.

Danke, das ist nett von dir. leider ist das eine Plugin sehr komplex. ich versuche das mal in 2 testPlugins nachzubauen und schicke sie dir dann gern.&nbsp;

---

<div class="post-metadata">

**Author:** ![hbee](https://avatars.discourse-cdn.com/v4/letter/h/f08c70/32.png) [@hbee](https://forum.shopware.com/u/hbee)\
**Post date:** [29. August 2017 um 11:43 UTC](https://forum.shopware.com/t/auf-klasse-aus-anderem-plugin-in-console-comand-zugreifen/47885/8 "2017-08-29T11:43:12Z")

</div>

ok, ich habe das jetzt noch mal in simplen Plugins nachgebaut. Hier funktioniert es. Da muss ich noch mal schauen wo der fehler liegt. Vielen Dank erst einmal.
