我试图按照https://symfony.com/doc/2.4/components/dependency_injection/parentservices.html#overriding-parent-dependencies覆盖服务定义 这是我的配置:
// services.yaml
services:
# default configuration for services in *this* file
_defaults:
autowire: true # Automatically injects dependencies in your services.
autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
public: false # Allows optimizing the container by removing unused services; this also means
# fetching services directly from the container via $container->get() won't work.
# The best practice is to be explicit about your dependencies anyway.
# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests}'
# controllers are imported separately to make sure services can be injected
# as action arguments even if you don't extend any base controller class
App\Controller\:
resource: '../src/Controller'
tags: ['controller.service_arguments']
# add more service definitions when explicit configuration is needed
# please note that last definitions always *replace* previous ones
imports:
- {resource: 'clients.yaml'}
// clients.yaml
services:
App\Api\Client\AbstractClient:
abstract: true
arguments:
- '@serializer'
- '@httplug.client.app'
App\Api\Client\MyClient:
parent: App\Api\Client\AbstractClient
calls:
- [setApiHost, ['%client.api_url%']]
正如你所看到的,我有两个类,其中一个是抽象的父类。
这似乎设置正确(成功覆盖):
Information for Service "App\Api\Client\AbstractClient"
=======================================================
---------------- ------------------------------------------
Option Value
---------------- ------------------------------------------
Service ID App\Api\Client\AbstractClient
Class App\Api\Client\AbstractClient
Tags -
Public yes
Synthetic no
Lazy no
Shared yes
Abstract yes
Autowired no
Autoconfigured no
Arguments Service(serializer)
Service(httplug.client.app.http_methods)
这个课程说它是自动装配的& autoconfigured但它(正确)继承了我AbstractClient
的参数,但它没有实现任何setter注入定义!
Information for Service "App\Api\Client\MyClient"
=========================================================
---------------- ------------------------------------------
Option Value
---------------- ------------------------------------------
Service ID App\Api\Client\MyClient
Class App\Api\Client\MyClient
Tags -
Public no
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired yes
Autoconfigured yes
Arguments Service(serializer)
Service(httplug.client.app.http_methods)
有人可以指导我为什么我的孩子班级没有被正确覆盖?