# Class used for service cannot be found

**URL:** <https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326>\
**Category:** Programmierung\
**Tags:** programming\
**Created:** [19. Juni 2024 um 13:15 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326 "2024-06-19T13:15:19Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![thomas.kipp](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@thomas.kipp](https://forum.shopware.com/u/thomas.kipp)\
**Post date:** [19. Juni 2024 um 13:15 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/1 "2024-06-19T13:15:19Z")

</div>

Hallo, mitten im laufenden Betrieb vermeldete ein Plugin folgende Errormeldung:

```auto
 Class "thomas_kipp\Subscriber\CustomerRegistration" used for service "WtCustomerRegistration
  \Subscriber\CustomerRegistration" cannot be found.

```

Es lief bereits mit folgender Konfiguration:  
composer.json:

```auto
{
    "name": "thomas_kipp/thomas_kipp",
    "description": "Deactivate customer account",
    "authors": [
        {
            "name": "Kipp,Thomas",
            "email": "thomas.kipp@xxx.de",
            "homepage": "https://xxx.de",
            "role": "Developer"
        }
    ],
    "type": "shopware-platform-plugin",
    "version": "1.0.0",
    "license": "MIT",
    "require": {
        "shopware/core": "6.*.*"
    },
    "extra": {
        "shopware-plugin-class": "thomas_kipp\\thomas_kipp",
        "label": {
            "de-DE": "Product Registration Plugin",
            "en-GB": "Product Registration Plugin"
        }
    },
    "autoload": {
        "psr-4": {
            "thomas_kipp\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "thomas_kipp\\Tests\\": "tests/"
        }
    }
}

```

services.xml

```auto
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>

        <service id="thomas_kipp\Subscriber\CustomerRegistration">
            <argument type="service" id="thomas_kipp\Service\Mailer"/>
            <argument type="service" id="thomas_kipp\Service\ContactDatabase"/>
            <tag name="kernel.event_subscriber"/>
        </service>
        <service id="thomas_kipp\Service\Mailer">
          <argument id="Shopware\Core\Content\MailTemplate\Service\MailService" type="service"/>
        </service>
        <service id="thomas_kipp\Service\ContactDatabase">
            <argument type="service" id="customer.repository"/>
        </service>
    </services>
</container>

```

Subscriber:

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

namespace thomas_kipp\Subscriber;

use Symfony\Component\HttpFoundation\Response;
use Shopware\Core\Checkout\Customer\Event\CustomerRegisterEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use WtCustomerRegistration\Service\Mailer;
use WtCustomerRegistration\Service\ContactDatabase;
use DateTime;
use DateInterval;
use Throwable;

/**
 *
 */
class CustomerRegistration implements EventSubscriberInterface
{
...
}

```

Es ist eine 1:1 Kopie meines lokalen Entwicklungsservers, wo alles famos läuft. Wie kommt es zu dieser Fehlermeldung?

---

<div class="post-metadata">

**Author:** ![thomas.kipp](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@thomas.kipp](https://forum.shopware.com/u/thomas.kipp)\
**Post date:** [19. Juni 2024 um 14:18 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/2 "2024-06-19T14:18:05Z")

</div>

Was auch immer der Grund war, ich habe es jetzt gefixt, indem ich einfach meine funktionierende Entwicklungsversion wieder hochgeladen habe. Der Error ist weg.  
Allerdings wurde in der Shopware6.3 Version noch ein Interface **und** eine Mailer Klasse verwendet. Ab Shopware6.5 gibt es kein Mail Interface mehr. Meine services.xml hat sich nicht verändert. Ich frage mich allerdings, was ich jetzt über eine DPI einlesen soll: Das Interface oder die Klasse, also so:

```auto
<?php

namespace WtCustomerRegistration\Service;

use Shopware\Core\Content\MailTemplate\Service\ **MailService** ;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\ParameterBag;
use DateTime;
use DateInterval;
use Exception;

class Mailer
{
    private **MailService** $mailService;

    public function __construct( **MailService** $mailService)
    {
        $this->mailService = $mailService;
    }

    /**
     * @param SalesChannelContext $salesChannelContext
     * @param string $subject
     * @param string $content
     * @param array $recipients
     * @return bool
     */
    public function sendMail(SalesChannelContext $salesChannelContext, string $subject, string $content, array $recipients): bool
    {
...
}

```

oder so:

```auto
<?php

namespace WtCustomerRegistration\Service;

use Shopware\Core\Content\MailTemplate\Service\ **MailServiceInterface** ;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\HttpFoundation\ParameterBag;
use DateTime;
use DateInterval;
use Exception;

class Mailer
{
    private **MailServiceInterface** $mailService;

    public function __construct( **MailServiceInterface** $mailService)
    {
        $this->mailService = $mailService;
    }

    /**
     * @param SalesChannelContext $salesChannelContext
     * @param string $subject
     * @param string $content
     * @param array $recipients
     * @return bool
     */
    public function sendMail(SalesChannelContext $salesChannelContext, string $subject, string $content, array $recipients): bool
    {
...
}

```

---

<div class="post-metadata">

**Author:** ![Anotherone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Anotherone](https://forum.shopware.com/u/Anotherone)\
**Post date:** [19. Juni 2024 um 21:04 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/3 "2024-06-19T21:04:16Z")

</div>

Fürs 6.5? Da wird wohl die abstract Klasse verwendet

```auto
private readonly AbstractMailService $emailService

```

---

<div class="post-metadata">

**Author:** ![thomas.kipp](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@thomas.kipp](https://forum.shopware.com/u/thomas.kipp)\
**Post date:** [20. Juni 2024 um 06:42 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/4 "2024-06-20T06:42:28Z")

</div>

Sorry, das war wohl missverständlich formuliert: Ich benötige diejenige Klasse, die für Shopware6.3.30 verwendet wird:

das Interface oder die Klasse, also so:

```auto
       <service id="WtCustomerRegistration\Service\Mailer">
            <argument id="Shopware\Core\Content\MailTemplate\Service\MailServiceInterface" type="service"/>
        </service>

```

oder so

```auto
       <service id="WtCustomerRegistration\Service\Mailer">
            <argument id="Shopware\Core\Content\MailTemplate\Service\MailService" type="service"/>
        </service>

```

> [@Anotherone](#):
>
> Fürs 6.5? Da wird wohl die abstract Klasse verwendet
> 
> ```auto
> private readonly AbstractMailService $emailService
> 
> ```

Diese Klasse implementiert die Versandmethode nicht. Genau so wenig wie das Interface. Sollte man nicht diejenige Klassse verwenden, die die Versandmethode implementiert?

---

<div class="post-metadata">

**Author:** ![Anotherone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Anotherone](https://forum.shopware.com/u/Anotherone)\
**Post date:** [20. Juni 2024 um 16:14 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/5 "2024-06-20T16:14:08Z")

</div>

Ach so, Du brauchst es für den 6.3? Das hab ich falsch verstanden. Da müsstest Du mal im Code in den originalen xml-Dateien schauen.

---

<div class="post-metadata">

**Author:** ![thomas.kipp](https://avatars.discourse-cdn.com/v4/letter/t/b5e925/32.png) [@thomas.kipp](https://forum.shopware.com/u/thomas.kipp)\
**Post date:** [20. Juni 2024 um 20:23 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/6 "2024-06-20T20:23:54Z")

</div>

Was denn für XML Dateien??  
Mit dieser service.xml klappt durch DPI der Mailversand:

```auto
<?xml version="1.0" ?>

<container xmlns="http://symfony.com/schema/dic/services"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

    <services>

        <service id="WtCustomerRegistration\Subscriber\CustomerRegistration">
            <argument type="service" id="WtCustomerRegistration\Service\Mailer"/>
            <argument type="service" id="WtCustomerRegistration\Service\ContactDatabase"/>
            <tag name="kernel.event_subscriber"/>
        </service>
        <service id="WtCustomerRegistration\Service\Mailer">
            <argument id="Shopware\Core\Content\MailTemplate\Service\MailService" type="service"/>
        </service>
        <service id="WtCustomerRegistration\Service\ContactDatabase">
            <argument type="service" id="customer.repository"/>
        </service>
    </services>
</container>

```

---

<div class="post-metadata">

**Author:** ![Anotherone](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@Anotherone](https://forum.shopware.com/u/Anotherone)\
**Post date:** [20. Juni 2024 um 22:24 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/7 "2024-06-20T22:24:21Z")

</div>

Die für die DI, da kann man ja schauen, wie Shopware das macht. Im 6.5 ist das in vendor/shopware/storefront/DependencyInjection, ich meine im 6.3 war es aber noch woanders.

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/shopware/original/3X/2/9/29c7587ba660f00e4995d1743162782e5d6d8653.svg) [@system](https://forum.shopware.com/u/system)\
**Post date:** [20. Juli 2024 um 22:25 UTC](https://forum.shopware.com/t/class-used-for-service-cannot-be-found/104326/8 "2024-07-20T22:25:15Z")

</div>

Dieses Thema wurde automatisch 30 Tage nach der letzten Antwort geschlossen. Es sind keine neuen Antworten mehr erlaubt.
