6cc9dc7586
This PR was merged into the 3.3-dev branch.
Discussion
----------
[DI] Add "by-id" autowiring: a side-effect free variant of it based on the class<>id convention
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets | -
| License | MIT
| Doc PR | -
This PR adds a new autowiring mode, based only on the class <> id convention.
This way of autowiring is free from any conflicting behavior, which is what I was looking for to begin with.
The expected DX is a bit more involving than the current way we do autowiring. But it's worth it to me, because it's plain predictable - a lot less "magic" imho.
So in this mode, for each `App\Foo` type hint, a reference to an "App\Foo" service will be created. If no such service exists, an exception will be thrown. To me, this opens a nice DX: when type hinting interfaces (which is the best practice), this will tell you when you need to create the explicit interface <> id mapping that is missing - thus encourage things to be made explicit, but only when required, and gradually, in a way that will favor discoverability by devs.
Of course, this is opt-in, and BC. You'd need to do eg in yaml: `autowire: by_id`.
For consistency, the current mode (`autowire: true`) can be configured using `autowire: by_type`.
Commits
-------
|
||
---|---|---|
.. | ||
extension1 | ||
extension2 | ||
extensions | ||
class_from_id.xml | ||
legacy_invalid_alias_definition.xml | ||
namespaces.xml | ||
nonvalid.xml | ||
services1.xml | ||
services2.xml | ||
services3.xml | ||
services4_bad_import.xml | ||
services4.xml | ||
services5.xml | ||
services6.xml | ||
services7.xml | ||
services8.xml | ||
services9.xml | ||
services10.xml | ||
services13.xml | ||
services14.xml | ||
services21.xml | ||
services22.xml | ||
services23.xml | ||
services24.xml | ||
services29.xml | ||
services_deprecated.xml | ||
services_instanceof.xml | ||
services_named_args.xml | ||
services_prototype.xml | ||
tag_with_empty_name.xml | ||
tag_without_name.xml | ||
with_key_outside_collection.xml | ||
withdoctype.xml | ||
xml_with_wrong_ext.php |