Public 服务作为私人处理

Public service is handled as private

我有两个 Symfony 应用程序使用的库,这个库定义了一组我想成为的服务 public(我希望能够直接通过容器检索它们。当我尝试访问一项服务我有这个:

The "Library\Service\DerivedServices\OneSpecificImplementation" service or alias has been removed or inlined when the container was compiled. You should either make it public, or stop using the container directly and use dependency injection instead.

问题是所述服务 声明的 public。

基本上有:

这是我的服务定义:

# Base: inject common dependencies
Library\Service\BaseService:
  abstract: true
  calls:
    - [setDoctrine, ['@doctrine.orm.entity_manager']]
    - [setLogger, ['@Library\Service\Logger']]

# These services are public to be retrieved directly by the container interface
Library\Service\DerivedServices\:
  resource: '../vendor/company/library/src/Library/Service/DerivedServices'
  public: true
  autowire: true
  autoconfigure: false
  parent: Library\Service\BaseService

然后,Symfony 应用程序检索一项派生服务,例如:

$this->get('Library\Service\DerivedServices\OneSpecificImplementation');

这些没有任何区别:

我认为这在配置方面是微不足道的,但我无法确定它(在尝试调试为什么框架将我的服务编译为私有服务 2 小时后,我认为有人可能有这个并且可能会提供帮助我)。

原来服务声明的顺序很重要。正如我所想,问题出在配置方面。

我有:

Library\Service\BaseService:
  ...

Library\Service\DerivedServices\:
  ...

Library\Service\:
  resource: '../vendor/company/library/src/Library/Service'

最后一条指令将所有服务重新声明为私有(默认)。
我将其更改为:

Library\Service\:
  resource: '../vendor/company/library/src/Library/Service'

Library\Service\BaseService:
  ...

Library\Service\DerivedServices\:
  ...

这首先将所有服务声明为私有,然后使用新声明重新声明它们:use of parent + public.