Symfony 4导入的.yaml服务正在自动装配

时间:2018-11-28 12:59:19

标签: symfony dependency-injection autowired monolog

services.yaml

imports:
    - { resource: commands.yaml }

parameters:

services:
    _defaults:
        autowire: true     
        autoconfigure: true 
        public: false       

    App\:
        resource: '../src/*'
        exclude: '../src/{Entity,Migrations,Tests}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    App\Service\ExampleService:
        arguments:
            - '%env(URL)%'
            - '@doctrine.orm.entity_manager'

commands.yaml

parameters:

services:

    App\Command\Import\ExampleCommand:
        arguments:
            - '@App\Service\ExampleService'
            - '@monolog.logger.example'
            - '@parameter_bag'

当我运行ExampleCommand时,monolog实例默认为默认渠道。我认为ExampleCommand获得不同记录器的原因是自动装配。当我注释- { resource: commands.yaml }时,命令运行没有错误。我有很多服务,需要分开配置。

一切正常,无需导入:

services.yaml

imports:
    - { resource: commands.yaml }

parameters:

services:
    _defaults:
        autowire: true     
        autoconfigure: true 
        public: false       

    App\:
        resource: '../src/*'
        exclude: '../src/{Entity,Migrations,Tests}'

    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    App\Service\ExampleService:
        arguments:
            - '%env(URL)%'
            - '@doctrine.orm.entity_manager'  

    App\Command\Import\ExampleCommand:
        arguments:
            - '@App\Service\ExampleService'
            - '@monolog.logger.example'
            - '@parameter_bag'

有很多进口的.yaml吗?

0 个答案:

没有答案
相关问题