struct X: XType { } protocol YType { } class Y: YType { let x: XType init(x: XType) { self.x = x } } protocol ZType { } class Z: ZType { let y: YType init(y: YType) { self.y = y } } import Swinject let container = Container() container.register(XType.self) { _ in X() } container.register(YType.self) { r in Y(x: r.resolve(XType.self)!) } container.register(ZType.self) { r in Z(y: r.resolve(YType.self)!) } Registration: Resolution: let z = container.resolve(ZType)! Type definition: Y→X Z→Y X Automatically resolved: Z→Y→X X Y Z
http://qiita.com/yoichitgy/items/ed8aac4d6f1e6666a4aa • Dependency Injection in Swift (Tokyo iOS Meetup) https://speakerdeck.com/yoichitgy/dependency-injection-in-swift • Unit Testing in Swift: Dependency Injection https://www.natashatherobot.com/unit-testing-swift-dependency-injection/ • DI in Scala: Cake Pattern pros & cons http://www.warski.org/blog/2011/04/di-in-scala-cake-pattern-pros-cons/ • You Used To Inject Me In Your Constructor (Reader Monad) https://speakerdeck.com/mathonsunday/you-used-to-inject-me-in-your-constructor