我有一个包含在私有Satis存储库中的包,因为它的实体和存储库在多个应用程序之间共享。Symfony 3.3将注入库注入服务
使用该捆绑包的其余应用程序是Symfony 2.7和2.8应用程序。我正在开发一个新的应用程序,并且要求使用Symfony 3.3。
在symfony的3.3应用程序,我已经在我的services.yml试过这样:
# Learn more about services, parameters and containers at
# http://symfony.com/doc/current/service_container.html
parameters:
#parameter_name: value
services:
# default configuration for services in *this* file
_defaults:
autowire: true
autoconfigure: true
# this means you cannot fetch services directly from the container via $container->get()
# if you need to do this, you can override this setting on individual services
public: false
# makes classes in src/AppBundle available to be used as services
# this creates a service per class whose id is the fully-qualified class name
CbmLtd\UvmsBundle\:
resource: '../../vendor/cbmltd/uvms-bundle/*'
exclude: '../../vendor/cbmltd/uvms-bundle/{Entity,Repository}'
UvmsApiV1Bundle\:
resource: '../../src/UvmsApiV1Bundle/*'
exclude: '../../src/UvmsApiV1Bundle/{Entity,Repository}'
上面给出了以下异常:
不能自动装配服务 “UvmsApiV1Bundle \服务\ DealerService”:方法“__construct()”的参数“$ repository”引用类“CbmLtd \ UvmsBundle \ Repository \ DealerRepository”,但不存在这样的服务。它不能被自动注册,因为它来自不同的根名称空间。
好吧,所以我想我需要显式声明这个存储库作为服务。在Symfony 3.3文档中找不到有关将存储库声明为服务的任何内容,2.8语法也不起作用。
我将此添加到我的services.yml:
services:
...
CbmLtd\UvmsBundle\DealerRepository:
class: CbmLtd\UvmsBundle\Entity\DealerRepository
factory_service: doctrine.orm.entity_manager
factory_method: getRepository
arguments:
- CbmLtd\UvmsBundle\Entity\Dealer
但我仍然得到此异常:
不能自动装配服务 “UvmsApiV1Bundle \服务\ DealerService”:参数 “$库” 的方法“__construct()”引用类“CbmLtd \ UvmsBundle \ Repository \ DealerRepository”,但不存在此类服务。它不能被自动注册,因为它来自不同的根名称空间。
我无法对CbmLtd \ UvmsBundle进行任何更改,因为这是由多个应用程序使用的。任何帮助,将不胜感激。我从字面上花了几个小时,这是非常令人沮丧的。
得到了: “请加入到服务的类” car_base.app。因为我们可能需要根据编译时检查来添加方法调用,所以即使它是由工厂构建的(3.4) – itnelo