Skip to content

SeanROlszewski/AutoInjector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AutoInjector

A dead simple dependency injector in Swift with scoped bindings, ala Blindside

Example

import UIKit
import AutoInjector

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var injector = Injector()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        registerDependencies()

        window = UIWindow(frame: UIScreen.main.bounds)
        window?.rootViewController = injector.getInstance(for: ViewController.self)
        window?.makeKeyAndVisible()

        return true
    }

    private func registerDependencies() {
        injector.addDependency(for: Guitar.self, withInstance: Guitar(brand: "Gibson"))

        injector.addDependency(for: ViewController.self) {
            injector in
            let vc = ViewController(nibName: String.from(type: ViewController.self), bundle: nil)
            vc.guitar = injector.getInstance(for: Guitar.self)
            return vc
        }
    }
}

About

A dead simple dependency injector in Swift

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published