Can custom services be autowired into another service in Symfony?

  • Page Owner: Not Set
  • Last Reviewed: 2018-08-30

I have a custom service ct_file_store.s3 and an autowired service which has no explicitly defined name or parameters. Can my custom service be injected into my autowired service without extra config?


Answer

I did some digging... some extra config is required. The good news is that the autowired service that needs the new custom service (ct_file_store.s3) does not have to be converted to a manually configured service. It is possible to manually configure only a single service (or multiple if desired), and keep the rest of the arguments autowired.

The new service definition would end up looking something like this:

My\Service\Name
    arguements:
        $nameOfInjectedVariable: '@ct_file_store.s3'

Symfony doc for reference