Home

Awesome

Fiery Crucible

A minimalist type safe Swift dependency injector factory. Where all true instances are forged.

Carthage compatible

Changelog

Version 3.0.2
Version 3.0.1
Version 3.0.0
Version 2.1.3
Version 2.1.2
Version 2.1.1
Version 2.1.0
Version 2.0.4
Version 2.0.3
Version 2.0.2
Version 2.0.0
Version 1.3.3
Version 1.3.2
Version 1.3.1
Version 1.3.0
Version 1.2.0

Features

Circular Dependencies

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.

How to use

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.

A code example

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
    }
}