Symfony容器定义方法未调用未注入服务
在开始有关Symfony的GitHub的任何讨论之前,我想澄清情况 并确保我真的找到了一个没有解决方案的问题。
当我们有一个服务容器定义时,该定义不会在任何地方注入 然后,其配置为由addMethodCall
在编译器通行证中调用的任何方法都不会调用。 即使我们为public
(在容器中保留服务)的服务也不会改变情况。
当然这是有道理的,但是根据这种行为,我无法实现以下插入:
- 有
服务A
具有相关编译器 - 通行定义要调用
somemethoda()
通过应用其addmethodcall()
函数 somemethod()
正在添加服务>服务b
到服务中存在的集合A
- 到目前为止的运行良好,但是...
- 任何
服务B
实例都没有在任何地方注入(它们仅收集通过服务a
在其集合中的方法) 服务b
的实例还包含其自己的编译器通行证,与服务a
将其定义配置为调用somemethodb()
,- 不幸的是,根据开头描述的事实,关于未注入未注入的定义未调用配置的方法 - 遇到一个不调用
的问题somemethodb()
,因此所有实例服务b
都有空的相关服务集合,以防止应用程序正确工作
问题:我如何确保不这样做注入的服务定义将调用配置的方法,因此它包含所有需要的内容(例如其内部集合), 当其他一些服务将实现此定义时,期望其收集初始化?
注意:我试图将未注入的服务设置为public
而不是懒惰
,我还尝试在容器中手动注册它们并运行相关的编译器在删除过程之前通过100%确定它们已经到位(实际上它们是缺少服务的问题,但事实上定义没有调用其配置的方法)。
Symfony 4.4.21
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 A
which has related compiler pass and it is injected into some other service - Compiler pass configures
Service A
definition to callsomeMethodA()
by applying itsaddMethodCall()
function someMethod()
is adding instances ofService B
to a collection existing withinService A
- Until now it works perfectly fine, but...
- Any of
Service B
instances are not injected anywhere (they are only collected byService A
method within its collection) - Instances of
Service B
also contains their own compiler passes which the same as forService A
configure 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 B
have 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论