SwiftSuspenders:“相互注入”课程?
SwiftSuspenders 是否支持“相互注入”类?
例如,如果类 A
注入 B
的实例,并且 B
注入 A
的实例:
class A {
[Inject]
public var b:B;
}
class B {
[Inject]
public var a:A;
}
并且,如果不是,我该如何伪造这种行为?
我问这个问题是因为,当我尝试在代码中执行此操作时,我开始出现堆栈溢出......而且看起来它们是由 SwiftSuspenders 试图将 A
注入 B
引起的进入A
进入B
进入...
Does SwiftSuspenders support “mutually injecting” classes?
For example, if class A
injects an instance of B
, and B
injects an instance of A
:
class A {
[Inject]
public var b:B;
}
class B {
[Inject]
public var a:A;
}
And, if not, how can I fake this behaviour?
I ask because, when I tried to do this in my code, I started getting stack overflows… And it looks like they are being caused by SwiftSuspenders trying to inject A
into B
into A
into B
into…
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简短的回答可能是否定的。循环依赖是一个技巧。您可以使用 setter 注入并以这种方式交付它。通过 setter 将 A 注入 B,该 setter 也会在 A 上设置 B。
可能值得提交 SS 问题来解决此类问题。
The short answer is probably no. Circular dependencies are a trick. You could use setter injection and deliver it that way. Inject A into B via a setter that also sets B on A.
It might be worth filing a SS issue to resolve this type of thing.