@@ -46,10 +46,6 @@ class ClientImp: Client {
46
46
*/
47
47
public final class Injected < T> : _InjectedPropertyBox {
48
48
49
- static var tag : DependencyContainer . Tag {
50
- return . String( " \( Injected< T> . self ) " )
51
- }
52
-
53
49
var _value : Any ?
54
50
55
51
public var value : T ? {
@@ -101,10 +97,6 @@ public final class InjectedWeak<T>: _InjectedWeakPropertyBox {
101
97
//so we just rely on user reading documentation and passing AnyObject in runtime
102
98
//also we will throw fatal error if type can not be casted to AnyObject during resolution
103
99
104
- static var tag : DependencyContainer . Tag {
105
- return . String( " \( InjectedWeak< T> . self ) " )
106
- }
107
-
108
100
weak var _value : AnyObject ?
109
101
110
102
public var value : T ? {
@@ -150,7 +142,7 @@ extension DependencyContainer {
150
142
public func resolveDependencies( instance: Any ) {
151
143
for child in Mirror ( reflecting: instance) . children {
152
144
do {
153
- try ( child. value as? _AutoInjectedPropertyBox ) ? . resolve ( self )
145
+ try ( child. value as? _AnyInjectedPropertyBox ) ? . resolve ( self )
154
146
} catch {
155
147
print ( error)
156
148
}
@@ -190,28 +182,38 @@ extension DependencyContainer {
190
182
191
183
}
192
184
193
- protocol _AutoInjectedPropertyBox {
185
+ protocol _AnyInjectedPropertyBox : class {
194
186
func resolve( container: DependencyContainer ) throws
195
187
static var tag : DependencyContainer . Tag { get }
196
188
}
197
189
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 {
199
201
var _value : Any ? { get set }
200
202
}
201
203
202
204
extension _InjectedPropertyBox {
203
205
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
205
207
}
206
208
}
207
209
208
- protocol _InjectedWeakPropertyBox : class , _AutoInjectedPropertyBox {
210
+ protocol _InjectedWeakPropertyBox : _AnyInjectedPropertyBox {
209
211
weak var _value : AnyObject ? { get set }
210
212
}
211
213
212
214
extension _InjectedWeakPropertyBox {
213
215
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
215
217
}
216
218
}
217
219
0 commit comments