Autowire problem ? #5947

Closed
opened 2026-01-22 15:22:53 +01:00 by admin · 4 comments
Owner

Originally created by @public0 on GitHub (Apr 10, 2018).

Originally assigned to: @Ocramius on GitHub.

We decided to use work with YAML instead of Annotations and also not use autowire but instead register our services in services.yaml.

I made a custom query in a repo which i'm calling in a service which in turn is called in the controller.

Controller:

public function search($name)
    {
        $result = $this->tagService->search($name);
        var_dump($result);

        $response = [];
        return new ResponseService($response);
   }

TagService

    public function search($search)
    {
        try {
            return $this->entityManager->getRepository(Tag::class)->search($search);
        } catch (\Exception $e) {
            echo $e->getMessage();
        }
    }


TagRepository

class TagRepository extends ServiceEntityRepository
{
     public function __construct(RegistryInterface $registry)
     {
         parent::__construct($registry, Tag::class);
     }

    public function search($value)
    {
        return $this->createQueryBuilder('t')
            ->where('t.name LIKE :value')->setParameter('value', $value)
            ->orderBy('t.id', 'ASC')
            ->setMaxResults(10)
            ->getQuery()
            ->getResult()
        ;
    }
}

App\Entity\Tag

App\Entity\Tag:
type: entity
repositoryClass: App\Repository\TagRepository
id:
id:
type: integer
generator: { strategy: AUTO }
fields:

name:
type: string
length: 100

If my repo extends ServiceEntityRepository i get this where it says it can't find this service

The "App\Repository\TagRepository" entity repository implements "Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface", but its service could not be found. Make sure the service exists and is tagged with "doctrine.repository_service".

But if i extend EntityRepository instead of ServiceEntityRepository it works

Originally created by @public0 on GitHub (Apr 10, 2018). Originally assigned to: @Ocramius on GitHub. We decided to use work with YAML instead of Annotations and also not use autowire but instead register our services in services.yaml. I made a custom query in a repo which i'm calling in a service which in turn is called in the controller. Controller: ``` public function search($name) { $result = $this->tagService->search($name); var_dump($result); $response = []; return new ResponseService($response); } ``` TagService ``` public function search($search) { try { return $this->entityManager->getRepository(Tag::class)->search($search); } catch (\Exception $e) { echo $e->getMessage(); } } ``` TagRepository ``` class TagRepository extends ServiceEntityRepository { public function __construct(RegistryInterface $registry) { parent::__construct($registry, Tag::class); } public function search($value) { return $this->createQueryBuilder('t') ->where('t.name LIKE :value')->setParameter('value', $value) ->orderBy('t.id', 'ASC') ->setMaxResults(10) ->getQuery() ->getResult() ; } } ``` App\Entity\Tag > App\Entity\Tag: > type: entity > repositoryClass: App\Repository\TagRepository > id: > id: > type: integer > generator: { strategy: AUTO } > fields: > > name: > type: string > length: 100 > If my repo extends ServiceEntityRepository i get this where it says it can't find this service The "App\Repository\TagRepository" entity repository implements "Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface", but its service could not be found. Make sure the service exists and is tagged with "doctrine.repository_service". But if i extend EntityRepository instead of ServiceEntityRepository it works
admin added the Invalid label 2026-01-22 15:22:53 +01:00
admin closed this issue 2026-01-22 15:22:54 +01:00
Author
Owner

@Nek- commented on GitHub (Apr 10, 2018):

Hello,

This problem is not related to Doctrine itself but to the DoctrineBundle of Symfony.

If you have questions, consider StackOverflow or the Slack chat of Symfony. Also please give more information next time because without your service definition and namespaces it's not possible to help you on a problem of service declaration :) .

Please close this issue as it is not related to Doctrine at all.

PS: You can enable syntax coloration of the code by using better the markdown. That would be great for your next messages.

@Nek- commented on GitHub (Apr 10, 2018): Hello, This problem is not related to Doctrine itself but to the [DoctrineBundle](https://github.com/doctrine/DoctrineBundle) of Symfony. If you have questions, consider [StackOverflow or the Slack chat of Symfony](https://symfony.com/community). Also please give more information next time because without your service definition and namespaces it's not possible to help you on a problem of service declaration :) . Please close this issue as it is not related to Doctrine at all. _PS: You can enable syntax coloration of the code by using better the markdown. That would be great for your next messages._
Author
Owner

@Ocramius commented on GitHub (Apr 10, 2018):

Closing as per @Nek-'s comment

@Ocramius commented on GitHub (Apr 10, 2018): Closing as per @Nek-'s comment
Author
Owner

@sewi-cpan commented on GitHub (Aug 16, 2019):

@Nek- An answer would have been great instead of linking to a chat. There's no answer on StackOverflow and no usable documentation. Could you edit and enhance your reply, please?

@sewi-cpan commented on GitHub (Aug 16, 2019): @Nek- An answer would have been great instead of linking to a chat. There's no answer on StackOverflow and no usable documentation. Could you edit and enhance your reply, please?
Author
Owner

@Nek- commented on GitHub (Aug 22, 2019):

@sewi-cpan a problem relative to user code without user code or reproducer is not resolvable. Sorry. I mentioned it btw.

Also please give more information next time because without your service definition and namespaces it's not possible to help you on a problem of service declaration :) .

Please, be kind with OSS contributors. We do our best, for free.

@Nek- commented on GitHub (Aug 22, 2019): @sewi-cpan a problem relative to user code without user code or reproducer is not resolvable. Sorry. I mentioned it btw. > Also please give more information next time because without your service definition and namespaces it's not possible to help you on a problem of service declaration :) . Please, be kind with OSS contributors. We do our best, for free.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5947