-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInjector.swift
44 lines (36 loc) · 943 Bytes
/
Injector.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Injector.swift
//
// Created by Phuong Lam on 4/14/19.
// Copyright © 2019 . All rights reserved.
//
class Injector {
private var binder: Binder
init(binder: Binder) {
self.binder = binder
}
func get<T>(_ type: T.Type, name: String = "") -> T? {
return binder.get(type, name: name)
}
static func builder() -> InjectorBuilder {
return InjectorBuilder()
}
}
class InjectorBuilder {
private var binder: Binder!
private var modules: [Module] = []
func withBinder(binder: Binder) -> InjectorBuilder {
self.binder = binder
return self
}
func withModule(_ modules: [Module]) -> InjectorBuilder {
self.modules = modules
return self
}
func build() -> Injector {
for module in modules {
module.configure(binder: binder)
}
return Injector(binder: binder)
}
}