@@ -39,8 +39,8 @@ public partial class UnityContainer
39
39
private readonly ContainerContext _context ;
40
40
41
41
// Strategies
42
- private readonly StagedStrategyChain < IBuilderStrategy , UnityBuildStage > _strategies ;
43
- private readonly StagedStrategyChain < IBuilderStrategy , BuilderStage > _buildPlanStrategies ;
42
+ private StagedStrategyChain < IBuilderStrategy , UnityBuildStage > _strategies ;
43
+ private StagedStrategyChain < IBuilderStrategy , BuilderStage > _buildPlanStrategies ;
44
44
45
45
// Events
46
46
private event EventHandler < RegisterEventArgs > Registering ;
@@ -68,11 +68,13 @@ private UnityContainer(UnityContainer parent)
68
68
_parent ? . _lifetimeContainer . Add ( this ) ;
69
69
70
70
// Strategies
71
- _strategies = new StagedStrategyChain < IBuilderStrategy , UnityBuildStage > ( _parent ? . _strategies ) ;
72
- _buildPlanStrategies = new StagedStrategyChain < IBuilderStrategy , BuilderStage > ( _parent ? . _buildPlanStrategies ) ;
71
+ _strategies = _parent ? . _strategies ;
72
+ _buildPlanStrategies = _parent ? . _buildPlanStrategies ;
73
+ _registerTypeStrategies = _parent ? . _registerTypeStrategies ;
74
+ _strategyChain = _parent ? . _strategyChain ;
73
75
74
76
// Lifetime
75
- _lifetimeContainer = new LifetimeContainer ( this ) { _strategies , _buildPlanStrategies } ;
77
+ _lifetimeContainer = new LifetimeContainer ( this ) ;
76
78
77
79
// Default Policies
78
80
if ( null == _parent ) InitializeRootContainer ( ) ;
@@ -84,7 +86,6 @@ private UnityContainer(UnityContainer parent)
84
86
_context = new ContainerContext ( this ) ;
85
87
86
88
// Caches
87
- OnStrategiesChanged ( this , null ) ;
88
89
_strategies . Invalidated += OnStrategiesChanged ;
89
90
}
90
91
@@ -95,6 +96,12 @@ private UnityContainer(UnityContainer parent)
95
96
96
97
protected void InitializeRootContainer ( )
97
98
{
99
+ // Initialize strategies
100
+ _strategies = new StagedStrategyChain < IBuilderStrategy , UnityBuildStage > ( ) ;
101
+ _buildPlanStrategies = new StagedStrategyChain < IBuilderStrategy , BuilderStage > ( ) ;
102
+ _lifetimeContainer . Add ( _strategies ) ;
103
+ _lifetimeContainer . Add ( _buildPlanStrategies ) ;
104
+
98
105
// Main strategy chain
99
106
_strategies . Add ( new BuildKeyMappingStrategy ( ) , UnityBuildStage . TypeMapping ) ;
100
107
_strategies . Add ( new LifetimeStrategy ( ) , UnityBuildStage . Lifetime ) ;
@@ -116,6 +123,10 @@ protected void InitializeRootContainer()
116
123
this [ typeof ( IEnumerable < > ) , string . Empty , typeof ( IBuildPlanCreatorPolicy ) ] =
117
124
new DelegateBasedBuildPlanCreatorPolicy ( typeof ( UnityContainer ) . GetTypeInfo ( ) . GetDeclaredMethod ( nameof ( ResolveEnumerable ) ) ,
118
125
context => context . BuildKey . Type . GetTypeInfo ( ) . GenericTypeArguments . First ( ) ) ;
126
+ // Caches
127
+ _registerTypeStrategies = _strategies . OfType < IRegisterTypeStrategy > ( ) . ToArray ( ) ;
128
+ _strategyChain = new StrategyChain ( _strategies ) ;
129
+
119
130
// Register this instance
120
131
RegisterInstance ( typeof ( IUnityContainer ) , null , this , new ContainerLifetimeManager ( ) ) ;
121
132
}
0 commit comments