-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[FrameworkBundle] Conflict between generated services ID #41198
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
@lyrixx There will be some BC changes then. From the
The documentation at this point clears it out: It's better to use If the service gets a prefix, it will break autowiring scoped clients by name. |
👍 for deprecating these services. With autowiring and named autowiring alias they are not needed IMHO |
@jderusse I disagree. The HttpClient is very special. It's decorated multiple times in FrameworkExtension. Also every client gets a special tag for the profiler. Everything is handled with configuration: simple and easy. The namespace is missing to allow this kind of autowiring. I am working on a project calling multiple APIs and all need their scoped client. How do I inject the specific client if I don't know its service name? Creating the scoped client by hand requires knowledge of its construction and the special tag. Not really useful. One idea might be to create an AbstractScopedHttpClient and each service must implement getBaseUri() method. But the cache pools? Hmm... |
For the record, this was discussed at the time and was a conscious decision, to not create any convention. You configure HTTP clients and cache pools giving them a plain service ID and that's the only knowledge you need to have. I agree there is an inconsistency with how eg workflows are wired, but my preference would be to actually deprecate the suffix/prefix convention there. Eg right now I'm forced to name my argument |
Even without a suffix it has to be "discovered/teached/learned". People are not strick with this knowledge 😇 But I agree with you about the hardcoded suffix that is less flexible. |
@nicolas-grekas If you want to deprecate suffix/prefix convention, you need to think about logging, too. Right now you can inject |
warning: There is a confusion here between the alias for argument registered, and the service ID. 1️⃣ Here, I was initially talking about the service ID only. This service id is used:
2️⃣ The alias for argument is fine, even if I think can enhance it. But the feature must be kept, of course! 3️⃣ But in both case, the same "name" is used for the service id and the alias for argument (except for workflow) For example: the following configuration framework:
cache:
pools:
github:
adapter: cache.adapter.redis
framework:
workflows:
rule: [...] The following generated services: <service id="github" class="Symfony\Component\Cache\Adapter\TraceableAdapter">
<!-- ... -->
</service>
<service id="state_machine.rule" class="Symfony\Component\Workflow\StateMachine" public="true">
<!-- ... -->
</service> and the following generated alias for argument:
I search in the framework bundle, and I found: So the framework configuration is not really consistant here. IMHO it be can be more predictable and consistant. The @nicolas-grekas solutions might be nice, because the end user have a full control on everything, but at the end, the configuration that we must write is really strange IMHO: framework:
messenger:
default_bus: command.bus
buses:
command.bus: []
query.bus: []
event.bus: [] The keyword So in order to find a solution I propose the following thing: In 5.4:
In 6.0:
Conclusion: in 6.0:
With that, I hope both @nicolas-grekas and me will be happy
|
the tricky things about not having a prefix in service ids is that the names you give to your HTTP clients, your cache pools and your messenger transport must now avoid conflicts with all service ids of the container. If you have a cache pool named
aren't you mixing the A and B cases here ? A already uses a prefix |
The WTF behavior might even be worse, as the |
@stof you are totally right, that's why I created the issue initially and want to get ride of this! And you are also right about |
Hey, thanks for your report! |
Could I get an answer? If I do not hear anything I will assume this issue is resolved or abandoned. Please get back to me <3 |
Hey, I didn't hear anything so I'm going to close it. Feel free to comment if this is still relevant, I can always reopen! |
Same topic on #44798 (comment) What would work I guess:
I guess we can deprecate the current names by using deprecated aliases. @lyrixx would that solve your issue? |
why ? it's very handy. and people already use it a lot (for monolog for instance) |
Because it reduces the DX by forcing ppl to learn about that prefix/suffix, and also because it forces ppl to use a specific name on their classes, eg |
I agree that the autowiring alias should be based on the user-defined name only. This is what gives the better DX by giving full control of this alias to the devs. And autowiring aliases don't suffer from conflicts, because the names only need to be unique by type, which is already the case in the config. |
Oh, I think I misunderstood what you said. If a workflow is named "foobar", then only the In that case, I agree with you 👍🏼 |
@lyrixx yes |
I did what proposed Nicolas (keeping the named autowiring alias to the user-defined name while adding a prefix to the service) in #44798, I agree it's probably the best scenario. |
I'm closing because I'm not sure it's worth improving. At least I'm not sure it's worth the cost of annoying ppl with deprecations. |
Symfony version(s) affected: all
Description
Symfony used to namespace all generated ID but it's not the case for some services
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Lines 2240 to 2249 in aea15bc
symfony/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php
Lines 2152 to 2156 in aea15bc
And maybe more
How to reproduce
With the previous configuration, http_client replaces the cache definition (because http client configuration is processed after cache configuration).
And If I change the name of the
github
http client:Possible Solution
We must namespace all services ID based on semantic configuration like we did in the past with messenger, workflow, etc
Additional context
This issue is a bit annoying with a different use case:
Once I declared a
github
client, I'm no longer able to usebin/console debug:container github
to find all services that matchgithub
because agithub
service exists. Yes, I can still use| grep github
, but still :)The text was updated successfully, but these errors were encountered: