Skip to content

Commit 099e0f6

Browse files
committed
minor internal protocols refactoring
1 parent 92f80e5 commit 099e0f6

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Dip/Dip/AutoInjection.swift

+16-14
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ class ClientImp: Client {
4646
*/
4747
public final class Injected<T>: _InjectedPropertyBox {
4848

49-
static var tag: DependencyContainer.Tag {
50-
return .String("\(Injected<T>.self)")
51-
}
52-
5349
var _value: Any?
5450

5551
public var value: T? {
@@ -101,10 +97,6 @@ public final class InjectedWeak<T>: _InjectedWeakPropertyBox {
10197
//so we just rely on user reading documentation and passing AnyObject in runtime
10298
//also we will throw fatal error if type can not be casted to AnyObject during resolution
10399

104-
static var tag: DependencyContainer.Tag {
105-
return .String("\(InjectedWeak<T>.self)")
106-
}
107-
108100
weak var _value: AnyObject?
109101

110102
public var value: T? {
@@ -150,7 +142,7 @@ extension DependencyContainer {
150142
public func resolveDependencies(instance: Any) {
151143
for child in Mirror(reflecting: instance).children {
152144
do {
153-
try (child.value as? _AutoInjectedPropertyBox)?.resolve(self)
145+
try (child.value as? _AnyInjectedPropertyBox)?.resolve(self)
154146
} catch {
155147
print(error)
156148
}
@@ -190,28 +182,38 @@ extension DependencyContainer {
190182

191183
}
192184

193-
protocol _AutoInjectedPropertyBox {
185+
protocol _AnyInjectedPropertyBox: class {
194186
func resolve(container: DependencyContainer) throws
195187
static var tag: DependencyContainer.Tag { get }
196188
}
197189

198-
protocol _InjectedPropertyBox: class, _AutoInjectedPropertyBox {
190+
extension _AnyInjectedPropertyBox {
191+
static var tag: DependencyContainer.Tag {
192+
return .String(String(self))
193+
}
194+
195+
func _resolve<T>(container: DependencyContainer) throws -> T {
196+
return try container.resolve(tag: self.dynamicType.tag) as T
197+
}
198+
}
199+
200+
protocol _InjectedPropertyBox: _AnyInjectedPropertyBox {
199201
var _value: Any? { get set }
200202
}
201203

202204
extension _InjectedPropertyBox {
203205
func resolve(container: DependencyContainer) throws {
204-
self._value = try container.resolve(tag: self.dynamicType.tag) as Any
206+
self._value = try _resolve(container) as Any
205207
}
206208
}
207209

208-
protocol _InjectedWeakPropertyBox: class, _AutoInjectedPropertyBox {
210+
protocol _InjectedWeakPropertyBox: _AnyInjectedPropertyBox {
209211
weak var _value: AnyObject? { get set }
210212
}
211213

212214
extension _InjectedWeakPropertyBox {
213215
func resolve(container: DependencyContainer) throws {
214-
self._value = try container.resolve(tag: self.dynamicType.tag) as AnyObject
216+
self._value = try _resolve(container) as AnyObject
215217
}
216218
}
217219

0 commit comments

Comments
 (0)