Question

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…

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top