admin管理员组

文章数量:1181449

I come here after a long day of debugging.

I get the following error on my Symfony 7 project:

Cannot autowire service "App\Infrastructure\Persistence\DoctrineConcreteRepository": argument "$entityManager" of method "__construct()" references interface  
   "Doctrine\ORM\EntityManagerInterface" but no such service exists. Did you create a class that implements this interface?             

I already installed doctrine/orm.

I configured the services.yaml:

Doctrine\ORM\EntityManagerInterface: '@doctrine.orm.default_entity_manager'

and doctrine.yaml:

doctrine:
  dbal:
    url: '%env(resolve:DATABASE_URL)%'
    driver: 'pdo_sqlite'
    charset: utf8mb4

  orm:
    auto_generate_proxy_classes: true
    naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
    auto_mapping: true
    default_entity_manager: default
    entity_managers:
      default:
        connection: default
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true

Then:

public function __construct(private Connection $connection, private EntityManagerInterface $entityManager)

And the services.yaml is quite simple:

services:
  _defaults:
    autowire: true
    autoconfigure: true

  App\Application\Repository\MyRepositoryInterface: '@App\Infrastructure\Persistence\MyDoctrineRepository'

  App\Infrastructure\Persistence\MyDoctrineRepository:
    arguments:
      $entityManager: '@doctrine.orm.default_entity_manager'

  Doctrine\ORM\EntityManagerInterface: '@doctrine.orm.default_entity_manager'

but when I clear the cache, or run the program, I get the error.

Any help?

本文标签: