Before I start any discussion on Symfony's Github, I would like to clarify the situation and make sure that I really found an issue for which there is no solution.
When we have a service container definition and that definition is not injected anywhere
then any of its methods configured to be called by addMethodCall within a compiler pass - won't be called.
Even if we make a service to be public (which preserves service in container) - it won't change the situation.
Of course it makes sense, but according to that behaviour I cannot achieve the following implemenation:
- There is
Service Awhich has related compiler pass and it is injected into some other service - Compiler pass configures
Service Adefinition to callsomeMethodA()by applying itsaddMethodCall()function someMethod()is adding instances ofService Bto a collection existing withinService A- Until now it works perfectly fine, but...
- Any of
Service Binstances are not injected anywhere (they are only collected byService Amethod within its collection) - Instances of
Service Balso contains their own compiler passes which the same as forService Aconfigure their definitions to callsomeMethodB()which are also collecting some other services - Unfortunately, according to the fact described at the beginning, about definitions not calling configured methods while they are not injected - makes a problem of not calling
someMethodB(), so all instances ofService Bhave empty collections of related services, preventing the application from working correctly
Question: how can I make sure that not injected service definition will call configured method, so it contains everything what is needed (like its inner collection), when some other service will take an instance of this definition, expecting it to have its collection initialized?
Notice: I was trying to set not injected services to be public and not lazy, I also tried to register them manually in the container and running related compiler passes before removal processes to be 100% sure that they are in place (and actually they are, I don't have problem with missing service, but with the fact that definition is not calling its configured method).
Symfony 4.4.21