@@ -72,10 +72,10 @@ private UnityContainer(UnityContainer parent)
7272 _buildPlanStrategies = new StagedStrategyChain < IBuilderStrategy , BuilderStage > ( _parent ? . _buildPlanStrategies ) ;
7373
7474 // Lifetime
75- _lifetimeContainer = new LifetimeContainer { _strategies , _buildPlanStrategies } ;
75+ _lifetimeContainer = new LifetimeContainer ( this ) { _strategies , _buildPlanStrategies } ;
7676
7777 // Default Policies
78- if ( null == _parent ) InitializeStrategies ( ) ;
78+ if ( null == _parent ) InitializeRootContainer ( ) ;
7979 _defaultPolicies = parent ? . _defaultPolicies ?? GetDefaultPolicies ( ) ;
8080 this [ null , null ] = _defaultPolicies ;
8181
@@ -86,17 +86,14 @@ private UnityContainer(UnityContainer parent)
8686 // Caches
8787 OnStrategiesChanged ( this , null ) ;
8888 _strategies . Invalidated += OnStrategiesChanged ;
89-
90- // Register this instance
91- RegisterInstance ( typeof ( IUnityContainer ) , null , this , new ContainerLifetimeManager ( ) ) ;
9289 }
9390
9491 #endregion
9592
9693
9794 #region Defaults
9895
99- protected void InitializeStrategies ( )
96+ protected void InitializeRootContainer ( )
10097 {
10198 // Main strategy chain
10299 _strategies . Add ( new BuildKeyMappingStrategy ( ) , UnityBuildStage . TypeMapping ) ;
@@ -119,6 +116,8 @@ protected void InitializeStrategies()
119116 this [ typeof ( IEnumerable < > ) , string . Empty , typeof ( IBuildPlanCreatorPolicy ) ] =
120117 new DelegateBasedBuildPlanCreatorPolicy ( typeof ( UnityContainer ) . GetTypeInfo ( ) . GetDeclaredMethod ( nameof ( ResolveEnumerable ) ) ,
121118 context => context . BuildKey . Type . GetTypeInfo ( ) . GenericTypeArguments . First ( ) ) ;
119+ // Register this instance
120+ RegisterInstance ( typeof ( IUnityContainer ) , null , this , new ContainerLifetimeManager ( ) ) ;
122121 }
123122
124123
0 commit comments