David Wolever
David Wolever

Reputation: 154494

SwiftSuspenders: “mutually injecting” classes?

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…

Upvotes: 1

Views: 244

Answers (1)

Joel Hooks
Joel Hooks

Reputation: 6565

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.

Upvotes: 2

Related Questions