11using System ;
22using System . Collections . Generic ;
3+ using System . Diagnostics . CodeAnalysis ;
34using System . Globalization ;
45using System . Linq ;
56using System . Reflection ;
@@ -66,16 +67,18 @@ public partial class UnityContainer
6667 internal BuilderStrategy [ ] _buildChain ;
6768
6869 // Methods
69- internal Func < Type , string , bool > IsTypeRegistered ;
7070 internal Func < Type , string , IPolicySet > GetRegistration ;
71- internal Func < IBuilderContext , object > BuilUpPipeline ;
71+ internal Func < IBuilderContext , object > BuildUpPipeline ;
7272 internal Func < INamedType , IPolicySet > Register ;
7373 internal GetPolicyDelegate GetPolicy ;
7474 internal SetPolicyDelegate SetPolicy ;
7575 internal ClearPolicyDelegate ClearPolicy ;
76+ internal Func < Type , string , bool > RegistrationExists ;
7677
7778 private Func < Type , string , IPolicySet > _get ;
7879 private Func < Type , string , Type , IPolicySet > _getGenericRegistration ;
80+ private Func < Type , bool > _isTypeExplicitlyRegistered ;
81+ private Func < Type , string , bool > _isExplicitlyRegistered ;
7982
8083 #endregion
8184
@@ -101,17 +104,18 @@ public UnityContainer()
101104 _buildPlanStrategies = new StagedStrategyChain < BuilderStrategy , BuilderStage > ( ) ;
102105
103106 // Methods
104- BuilUpPipeline = ThrowingBuildUp ;
105- IsTypeRegistered = IsTypeRegisteredLocally ;
107+ _get = Get ;
108+ _getGenericRegistration = GetOrAddGeneric ;
109+ _isExplicitlyRegistered = IsExplicitlyRegisteredLocally ;
110+ _isTypeExplicitlyRegistered = IsTypeTypeExplicitlyRegisteredLocally ;
111+
112+ BuildUpPipeline = ThrowingBuildUp ;
106113 GetRegistration = GetOrAdd ;
107114 Register = AddOrUpdate ;
108115 GetPolicy = Get ;
109116 SetPolicy = Set ;
110117 ClearPolicy = Clear ;
111-
112- _get = Get ;
113- _getGenericRegistration = GetOrAddGeneric ;
114-
118+ RegistrationExists = ( type , name ) => null != _get ( type , name ) ;
115119
116120 // TODO: Initialize disposables
117121 _lifetimeContainer . Add ( _strategies ) ;
@@ -165,16 +169,18 @@ private UnityContainer(UnityContainer parent)
165169 _root = _parent . _root ;
166170
167171 // Methods
168- BuilUpPipeline = _parent . BuilUpPipeline ;
169- IsTypeRegistered = _parent . IsTypeRegistered ;
172+ _get = _parent . _get ;
173+ _getGenericRegistration = _parent . _getGenericRegistration ;
174+ _isExplicitlyRegistered = _parent . _isExplicitlyRegistered ;
175+ _isTypeExplicitlyRegistered = _parent . _isTypeExplicitlyRegistered ;
176+
177+ BuildUpPipeline = _parent . BuildUpPipeline ;
170178 GetRegistration = _parent . GetRegistration ;
171179 Register = CreateAndSetOrUpdate ;
172180 GetPolicy = parent . GetPolicy ;
173181 SetPolicy = CreateAndSetPolicy ;
174182 ClearPolicy = delegate { } ;
175-
176- _get = _parent . _get ;
177- _getGenericRegistration = _parent . _getGenericRegistration ;
183+ RegistrationExists = ( type , name ) => null != _get ( type , name ) ;
178184
179185 // Strategies
180186 _strategies = _parent . _strategies ;
@@ -233,16 +239,17 @@ private IPolicySet CreateAndSetOrUpdate(INamedType registration)
233239 private void SetupChildContainerBehaviors ( )
234240 {
235241 _registrations = new HashRegistry < Type , IRegistry < string , IPolicySet > > ( ContainerInitialCapacity ) ;
236- IsTypeRegistered = IsTypeRegisteredLocally ;
237242 Register = AddOrUpdate ;
238243 GetPolicy = Get ;
239244 SetPolicy = Set ;
240245 ClearPolicy = Clear ;
241246
242247 GetRegistration = GetDynamicRegistration ;
243248
244- _get = GetChained ;
249+ _get = ( type , name ) => Get ( type , name ) ?? _parent . _get ( type , name ) ;
245250 _getGenericRegistration = GetOrAddGeneric ;
251+ _isTypeExplicitlyRegistered = IsTypeTypeExplicitlyRegisteredLocally ;
252+ _isExplicitlyRegistered = IsExplicitlyRegisteredLocally ;
246253 }
247254
248255 private void OnStrategiesChanged ( object sender , EventArgs e )
@@ -294,6 +301,7 @@ private IList<BuilderStrategy> GetBuilders(InternalRegistration registration)
294301 return chain ;
295302 }
296303
304+ [ SuppressMessage ( "ReSharper" , "InconsistentlySynchronizedField" ) ]
297305 internal Type GetFinalType ( Type argType )
298306 {
299307 Type next ;
@@ -302,18 +310,18 @@ internal Type GetFinalType(Type argType)
302310 var info = type . GetTypeInfo ( ) ;
303311 if ( info . IsGenericType )
304312 {
305- if ( IsRegistered ( type ) ) return type ;
313+ if ( _isTypeExplicitlyRegistered ( type ) ) return type ;
306314
307315 var definition = info . GetGenericTypeDefinition ( ) ;
308- if ( IsRegistered ( definition ) ) return definition ;
316+ if ( _isTypeExplicitlyRegistered ( definition ) ) return definition ;
309317
310318 next = info . GenericTypeArguments [ 0 ] ;
311- if ( IsRegistered ( next ) ) return next ;
319+ if ( _isTypeExplicitlyRegistered ( next ) ) return next ;
312320 }
313321 else if ( type . IsArray )
314322 {
315323 next = type . GetElementType ( ) ;
316- if ( IsRegistered ( next ) ) return next ;
324+ if ( _isTypeExplicitlyRegistered ( next ) ) return next ;
317325 }
318326 else
319327 {
@@ -336,6 +344,7 @@ internal Type GetFinalType(Type argType)
336344 /// This class doesn't have a finalizer, so <paramref name="disposing"/> will always be true.</remarks>
337345 /// <param name="disposing">True if being called typeFrom the IDisposable.Dispose
338346 /// method, false if being called typeFrom a finalizer.</param>
347+ [ SuppressMessage ( "ReSharper" , "InconsistentlySynchronizedField" ) ]
339348 protected virtual void Dispose ( bool disposing )
340349 {
341350 if ( ! disposing ) return ;
0 commit comments