【发布时间】:2019-06-28 21:19:50
【问题描述】:
在 Symfony 中覆盖父服务参数并向子服务参数添加更多参数的正确方法是什么?根据文档,我需要使用“index_N”。但是如何为子服务添加更多参数呢?例如:
config/services.yaml
服务: # ...
App\Repository\DoctrineUserRepository:
parent: App\Repository\BaseDoctrineRepository
# overrides the public setting of the parent service
public: false
# appends the '@app.username_checker' argument to the parent
# argument list
arguments: ['@app.username_checker']
App\Repository\DoctrinePostRepository:
parent: App\Repository\BaseDoctrineRepository
# overrides the first argument (using the special index_N key)
arguments:
index_0: '@doctrine.custom_entity_manager'
// put here more arguments for the child service
【问题讨论】:
标签: php symfony service dependency-injection