Skip to content

threeplay/TPInjector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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, eliran@threeplay.com

License

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

About

Simple Swift Dependency Injection Framework

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors