TestsTested | β |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Jan 2016 |
SPMSupports SPM | β |
Maintained by Sash Zats.
Warning: this project is not considered to be feature complete.
let applicationController = ApplicationController(
persistanceService: persistanceService,
analyticsService: analyticsService,
remoteConfigurationService: remoteConfigurationService,
authenticationController: authenticationController,
networkProvider: provider
)
let applicationController = try injector.inject(ApplicationController.init)
Please check out playground included with project for more examples.
let chicken = π()
injector.set(chicken)
// later in your code
let chicken: π = injector.get()
chicken.cockadoodle()
protocol ππ {
func peel()
}
struct π΅: ππ {
}
struct π¨: ππ {
}
injector.set(π΅())
injector.set(π¨())
let banana: ππ = injector.get(type: π¨.self)!
banana.peel()
Injector
can inject all the arguments for specified function using previously registered instances:
struct π¦ {
let heart: β€οΈ
let innerKitten: πΊ
init(heart: β€οΈ, innerKitten: πΊ) {
self.heart = heart
self.innerKitten = innerKitten
}
}
injector.set(β€οΈ())
injector.set(πΊ())
let lion = try injector.inject(π¦.init)
lion.meow()
If any of parameters is not registered with injector
, it will throw an InjectorError.TypeNotFound(T)
with first type injector failed to find. You are not limited to initializer, you can use any method (with up to 30 arguments)
inject
will get confused. As a possible workaround, you can define a convinience class function that doesnβt have any get
method is currently O(n). PRs on improving this one are very much welcome. The only limitation is not to use Objective-C runtime magic.