Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork5.3k
Description
Problem
The documentation regarding theautoconfigure option states the following regarding_defaults:
Above, the services.yaml file has autoconfigure: true in the _defaults section so that it applies to all services defined in that file. With this setting, the container will automatically apply certain configuration to your services, based on your service's class. This is mostly used to auto-tag your services.
(this is also denoted insymfony/symfony#28326 (comment) that the defaults are file-based)
With the introduction of usingwhen@<env> tags that can be used within the same file, likeservices.yaml file, this statement has become somewhat ambiguous, as_defaults does not (literally) apply to all services defined in the file. When settingautowire, it does only apply to the currentservices, not to the ones defined under the services ifwhen is used in the same file.
Working example:
services.yaml
services:# default configuration for services in *this* file; (this is the default comment from framework bundle recipe)_defaults:autowire:trueautoconfigure:trueApp\My\Service:# has arbitrary amount of argumentswhen@prod:services:_defaults:autowire:trueautoconfigure:trueApp\My\Service:# autowired arguments passed to service; works
Non-working example:
services.yaml
services:# default configuration for services in *this* file ; (this is the default comment from framework bundle recipe)_defaults:autowire:trueautoconfigure:trueApp\My\Service:# has arbitrary amount of argumentswhen@prod:services:App\My\Service:# no explicit arguments given thus failing with "ArgumentCountError" as not autowired
The wording...that it applies to all services defined in that file or# default configuration for services in *this* file (in theservices.yaml) makes it seems as if the "Non-working example" should have worked as everything is defined in thesame file (but it doesn't).
Suggestion
Add a note/warning to theautoconfigure option section that the_defaults need to be explicitely redefined when usingwhen in the sameservices.yaml.