-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Allow to bind inline services by type and name #40469
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
We might improve the error message, but what it says is that only references are allowed when binding services, and this looks legit to me. Otherwise, there is some non-intuitive issue that is going to happen, eg: should all inline services lead to different instances or should they all refer to the same one ? (note: this would need a ... reference). |
@nicolas-grekas, I understand your reasoning, but as a developer I face the following inconsistency. I can bind an inline service by name only, but cannot bind by type and name. So it would be more logical to forbid binding inline services completely, or allow to bind them both ways. |
Would you mind investigating in the code where this difference happens? I'm surprised that binding by name-only works with inline services. |
symfony/src/Symfony/Component/DependencyInjection/Loader/Configurator/Traits/BindTrait.php Lines 37 to 39 in 2dcf313
The first matching group in the regexp is optional. Thus, during a call |
PR welcome @vudaltsov, let's make this consistent. |
Currently it throws
Invalid binding for service "": named arguments must start with a "$", and FQCN must map to references. Neither applies to binding "Foo $foo"
, while binding inline service just by name works.The text was updated successfully, but these errors were encountered: