This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Dumper
Fabien Potencier 6cc9dc7586 feature #22060 [DI] Add "by-id" autowiring: a side-effect free variant of it based on the class<>id convention (nicolas-grekas)
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
-------

c298f2a90c [DI] Add "by-id" autowiring: a side-effect free variant of it based on the class<>id convention
2017-03-25 13:18:59 -07:00
..
Dumper.php [DependencyInjection] fix phpDoc 2016-04-11 16:45:49 +02:00
DumperInterface.php remove api tags from code 2015-09-28 19:11:22 +02:00
GraphvizDumper.php Revert "feature #20973 [DI] Add getter injection (nicolas-grekas)" 2017-03-25 15:07:47 +01:00
PhpDumper.php feature #22060 [DI] Add "by-id" autowiring: a side-effect free variant of it based on the class<>id convention (nicolas-grekas) 2017-03-25 13:18:59 -07:00
XmlDumper.php feature #22060 [DI] Add "by-id" autowiring: a side-effect free variant of it based on the class<>id convention (nicolas-grekas) 2017-03-25 13:18:59 -07:00
YamlDumper.php feature #22060 [DI] Add "by-id" autowiring: a side-effect free variant of it based on the class<>id convention (nicolas-grekas) 2017-03-25 13:18:59 -07:00