SwiftSuspenders:“相互注入”课程?

发布于 2024-10-03 13:35:10 字数 426 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

行雁书 2024-10-10 13:35:10

简短的回答可能是否定的。循环依赖是一个技巧。您可以使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文