1

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…

David Wolever
  • 148,955
  • 89
  • 346
  • 502

1 Answers1

1

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.

Joel Hooks
  • 6,465
  • 4
  • 33
  • 39