@@ -46,10 +46,12 @@ class ClientImp: Client {
4646*/
4747public  final  class  Injected < T> :  _Injected  { 
4848
49+   static  var  tag :  DependencyContainer . Tag  { 
50+     return  . String( " \( Injected< T> . self ) " ) 
51+   } 
52+ 
4953  var  _value :  Any ? 
5054
51-   public  init ( )  { } 
52-   
5355  public  var  value :  T ? { 
5456    get  { 
5557      return  _value as?  T 
@@ -58,7 +60,9 @@ public final class Injected<T>: _Injected {
5860      _value =  newValue
5961    } 
6062  } 
61-   
63+ 
64+   public  init ( )  { } 
65+ 
6266} 
6367
6468/**
@@ -97,10 +101,12 @@ public final class InjectedWeak<T>: _InjectedWeak {
97101  //so we just rely on user reading documentation and passing AnyObject in runtime
98102  //also we will throw fatal error if type can not be casted to AnyObject during resolution
99103
104+   static  var  tag :  DependencyContainer . Tag  { 
105+     return  . String( " \( InjectedWeak< T> . self ) " ) 
106+   } 
107+ 
100108  weak var  _value :  AnyObject ? 
101109
102-   public  init ( )  { } 
103-   
104110  public  var  value :  T ? { 
105111    get  { 
106112      return  _value as?  T 
@@ -109,7 +115,9 @@ public final class InjectedWeak<T>: _InjectedWeak {
109115      _value =  newValue as?  AnyObject 
110116    } 
111117  } 
112-   
118+ 
119+   public  init ( )  { } 
120+ 
113121} 
114122
115123extension  DependencyContainer  { 
@@ -140,16 +148,8 @@ extension DependencyContainer {
140148
141149   */
142150  public  func  resolveDependencies( instance:  Any )  { 
143-     for  child  in  Mirror ( reflecting:  instance) . children
144-       where  child. value is _Injected  || child. value is _InjectedWeak   { 
145-         
146-         let  tag  =  Tag . String ( " \( child. value. dynamicType) " ) 
147-         if  let  value =  child. value as?  _Injected  { 
148-           value. _value =  resolve ( tag:  tag)  as  Any 
149-         } 
150-         else  if  let  weakValue =  child. value as?  _InjectedWeak  { 
151-           weakValue. _value =  resolve ( tag:  tag)  as  AnyObject 
152-         } 
151+     for  child  in  Mirror ( reflecting:  instance) . children { 
152+       ( child. value as?  _AutoInjected ) ? . resolve ( self ) 
153153    } 
154154  } 
155155
@@ -162,11 +162,11 @@ extension DependencyContainer {
162162  typealias  InjectedWeakFactory  =  ( ) -> AnyObject 
163163
164164  static  func  injectedKey< T> ( type:  T . Type )  ->  DefinitionKey  { 
165-     return  DefinitionKey ( protocolType:  Any . self,  factoryType:  InjectedFactory . self,  associatedTag:  Tag . String ( injectedTag ( type ) ) ) 
165+     return  DefinitionKey ( protocolType:  Any . self,  factoryType:  InjectedFactory . self,  associatedTag:  Injected < T > . tag ) 
166166  } 
167167
168168  static  func  injectedWeakKey< T> ( type:  T . Type )  ->  DefinitionKey  { 
169-     return  DefinitionKey ( protocolType:  AnyObject . self,  factoryType:  InjectedWeakFactory . self,  associatedTag:  Tag . String ( injectedWeakTag ( type ) ) ) 
169+     return  DefinitionKey ( protocolType:  AnyObject . self,  factoryType:  InjectedWeakFactory . self,  associatedTag:  InjectedWeak < T > . tag ) 
170170  } 
171171
172172  func  registerInjected< T,  F> ( definition:  DefinitionOf < T ,  F > )  { 
@@ -191,19 +191,29 @@ extension DependencyContainer {
191191
192192} 
193193
194- func  injectedTag< T> ( type:  T . Type )  ->  String  { 
195-   return  " \( Injected < T > ( ) . dynamicType) " 
194+ protocol  _AutoInjected  { 
195+   func  resolve( container:  DependencyContainer ) 
196+   static  var  tag :  DependencyContainer . Tag  {  get  } 
196197} 
197198
198- func  injectedWeakTag < T > ( type :   T . Type )   ->   String  { 
199-   return   " \( InjectedWeak < T > ( ) . dynamicType ) " 
199+ protocol   _Injected :   class ,   _AutoInjected  { 
200+   var   _value :   Any ?   {   get   set   } 
200201} 
201202
202- protocol  _Injected :  class  { 
203-   var  _value :  Any ? {  get  set  } 
203+ extension  _Injected  { 
204+   func  resolve( container:  DependencyContainer )  { 
205+     self . _value =  container. resolve ( tag:  self . dynamicType. tag)  as  Any 
206+   } 
204207} 
205208
206- protocol  _InjectedWeak :  class  { 
209+ protocol  _InjectedWeak :  class ,   _AutoInjected  { 
207210  weak var  _value :  AnyObject ? {  get  set  } 
208211} 
209212
213+ extension  _InjectedWeak  { 
214+   func  resolve( container:  DependencyContainer )  { 
215+     self . _value =  container. resolve ( tag:  self . dynamicType. tag)  as  AnyObject 
216+   } 
217+ } 
218+ 
219+ 
0 commit comments