@mac
To enable autowiring in Symfony, you need to do the following:
- Enable the autowiring option in your services.yaml file. You can do this by setting the autowire option to true for a service definition:
1
2
3
|
services:
AppServiceSomeService:
autowire: true
|
- If you are using the Symfony Dependency Injection component version 4.3 or higher, you can also enable autowiring globally for your entire application by setting the autowiring option to true in the parameters section of your services.yaml file:
1
2
|
parameters:
autowiring: true
|
- If you want to autowire a specific argument of a service, you can use the autowire key in the argument's configuration:
1
2
3
4
5
|
services:
AppServiceSomeService:
arguments:
$dependency: '@AppServiceDependencyService'
$autowiredArgument: '@autowire'
|
- If you want to specify which specific service should be injected when autowiring, you can use the autowiring_types key in the service definition:
1
2
3
4
|
services:
AppServiceSomeService:
autowiring_types:
AppServiceDependencyService: '@AppServiceDependencyService'
|
That's it! Autowiring should now be enabled for your application.