Latest 1.0.0
Homepage https://github.com/achernoprudov/SwiftDI
License MIT
Platforms ios 8.0, osx 10.10, watchos 2.0, tvos 9.0
Authors

Travis CI
CocoaPods Version
License
Platforms
Swift Version

Simple dependency injection library for swift projects.

Example

Assemble dependencies

let injector = Injector()

injector.bind(ApiProtocol.self).with { _ in 
  return RestApi()
}
injector.bind(RepositoryProtocol.self).with { i in
  let api = i.resolve(ApiProtocol.self)
  return Repository(api: api) 
}

Inject dependencies to ViewController directly

class Controller: UIViewController {

  var injector: Injector! = ... // provide injector to VC
  var repository: RepositoryProtocol!

  func viewDidLoad() {
    super.viewDidLoad()
    repository = injector.resolve()
  }
}

Dependency injection options

injector.bind(ApiProtocol.self) // link with type
    .tag("some tag")            // link with custom string tag
    .singleton(true)            // define dependency as singleton
    .with { ... }               // initilization dependency closure

injector.resolve(ApiProtocol.self, tag: "some value") //resolving by type and tag 

CocoaPods

pod 'SwiftDI', '~> 1.0'

Latest podspec

{
    "name": "SwiftDI",
    "version": "1.0.0",
    "summary": "SwiftDI is a dependency manager for Swift projects.",
    "description": "SwiftDI is a dependency manager for Swift projects.nLibrary currently in development.",
    "homepage": "https://github.com/achernoprudov/SwiftDI",
    "license": "MIT",
    "authors": {
        "Andrey Chernoprudov": "[email protected]"
    },
    "platforms": {
        "ios": "8.0",
        "osx": "10.10",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/achernoprudov/SwiftDI.git",
        "tag": "1.0.0"
    },
    "source_files": "Source/**/*.{swift}"
}

Pin It on Pinterest

Share This