TPInjector 0.2.0

TPInjector 0.2.0

Maintained by Eliran Ben-Ezra.



  • By
  • Eliran Ben-Ezra

TPInjector

CI Status Version License Platform

Usage

To setup dependencies you set or register them on the DefaultInjector

  DefaultInjector.set(key: "api_key", to: "12345678")
  DefaultInjector.set(key: "api_url", to: NSURL(string: "https://someurl.com"))
  DefaultInjector.register(service: NetworkService.self, with: NetworkServiceImpl())
  DefaultInjector.register(service: LoginService.self, with: LoginServiceImpl())

To inject dependecies you add Injectable protocol to your class/struct definition and inject / tryInject static methods to inject dependencies:

class ClassWithDependecies: Injectable {

  private let networkService = inject(NetworkService.self)
  private let api_key = inject("api_key", String.self)
  private let api_url: NSURL = tryInject("api_url") ?? NSURL(string: "https://default.com")

  init(loginService: LoginService = inject()) {

  }
}

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

TPInjector is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'TPInjector'

Author

Eliran Ben-Ezra, [email protected]

License

TPInjector is available under the MIT license. See the LICENSE file for more info.