TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✓ |
Maintained by Justin Kolb.
A minimalist type safe Swift dependency injector factory. Where all true instances are forged.
Circular refrences are handled only by using setter injection. This works because all the instances are created in a construction phase before setter injection is triggered allowing references to exist before they are needed.
You can either copy the source into your project, or setup a git submodle of this repo and drag the project into your project as a subproject.
import FieryCrucible
import UIKit
class CustomFactory : DependencyFactory {
func application() -> CustomApplication {
return shared(CustomApplication()) { instance in
instance.factory = self
}
}
func mainWindow() -> UIWindow {
return shared(
factory: {
let instance = UIWindow(frame: UIScreen.mainScreen().bounds)
instance.backgroundColor = UIColor.whiteColor()
return instance
},
configure: { instance in
instance.rootViewController = self.rootViewController()
}
)
}
func rootViewController() -> UIViewController {
return scoped(UITabBarController()) { instance in
instance.viewControllers = [
self.tab0ViewController(),
self.tab1ViewController(),
]
}
}
...
}
class CustomApplication {
var factory: CustomFactory!
func launch() {
factory.mainWindow().makeKeyAndVisible()
}
}
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var factory: CustomFactory!
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
factory = CustomFactory()
factory.application().launch()
return true
}
}