我正在尝试将一个大的service.yaml拆分为几个小文件。在originservice.yaml中,我有
服务:
_defaults:
autowire: true
autoconfigure: true
public: false
App\Domain\Country\Infrastructure\Repository\CountryRepository:
public: true
class: App\Domain\Country\Infrastructure\Repository\CountryRepository
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [App\Domain\Country\Entity\Country]
然后我在开始的时候加入了进口服务。
imports:
- {resource: services/repositories.yaml}
repositories.yaml
services:
_defaults:
autowire: true
autoconfigure: true
public: true
App\Domain\Country\Infrastructure\Repository\CountryRepository:
factory: ["@doctrine.orm.default_entity_manager", getRepository]
arguments: [App\Domain\Country\Entity\Country]
在那之后我开始出错
Cannot autowire service "App\Domain\Country\Infrastructure\Repository\Count
ryRepository": argument "$class" of method "Doctrine\ORM\EntityRepository::
__construct()" references class "Doctrine\ORM\Mapping\ClassMetadata" but no
such service exists.
有什么问题吗?
- https://pastebin.com/Uy85YJmc(服务名称)
- https://pastebin.com/ZesAw3sD(存储库.yaml)
2条答案
按热度按时间xdnvmnnf1#
您不需要为了自动装配而定义存储库。
services.yaml:
实体\国家:
存储库\国家存储库:
最后,您的服务:
自动装配将看到您已经将
CountryRepository
注入到ExampleService
构造函数中,并处理其余部分。6yoyoihd2#
改用命名参数:
存储库.yaml