Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Swifjection

tgrf
October 03, 2018

 Swifjection

Dependency injection framework for Swift

tgrf

October 03, 2018

Transcript

17 slides
  1. Why? • missing reliable Swift DI solution back to the

    date • moving good practices from Objective-C code • simplify code testability • enforcing responsibility isolation • no need to inherit from NSObject in order to inject • conforming to Injectable protocol as the only requirement for pure-Swift injection 4
  2. 6 Who’s behind? • created by the former iOS team

    members
 
 
 • with a little help from our friends from the community • proudly maintained by Applause • main development done from November 2016 to April 2017
  3. 8 Features • Supported bindings: • type to type mapping

    (supports protocol-oriented programming) bindings.bind(object: MyClass.self, toType: MyProtocol.self) • instance to type mapping let object = MyClassConformingToMyProtocol() bindings.bind(object: object, toType: MyProtocol.self)
  4. 9 Features • Supported bindings: • closure to type mapping

    bindings.bind(type: ClassConformingToProtocol.self) { injector in let object = MyClass() object.doAdditionalWork() return object } • singleton binding bindings.bindSingleton(forType: MyClass.self)
  5. 10 Features • Creating objects using Swifjector: • with getObject(withType:)

    let object: MyClass? = injector.getObject(withType: MyClass.self) • using subscript let otherObject: MyClass? = injector[MyClass.self] as MyClass
  6. 11 Features • Injecting dependencies or being injected with only

    Injectable protocol conformance: protocol Injectable { init?(injector: Injecting) func injectDependencies(injector: Injecting) }
  7. Others 13 • Native Swift solutions: • https://github.com/square/Cleanse • https://github.com/Swinject/Swinject

    • https://github.com/appsquickly/TyphoonSwift • Objective-C with Swift support: • https://github.com/appsquickly/Typhoon
  8. Q&A

More Decks by tgrf

Other Decks in Programming