@@ -10,7 +10,7 @@ namespace Pure.DI.Core.Code;
1010using static LinesBuilderExtensions ;
1111
1212class RootBuilder (
13- INodeInfo nodeInfo ,
13+ INodeTools nodeTools ,
1414 IBuildTools buildTools ,
1515 IAccumulators accumulators ,
1616 ILocks locks ,
@@ -27,6 +27,7 @@ class RootBuilder(
2727 INameProvider nameProvider ,
2828 IOverridesRegistry overridesRegistry ,
2929 INameFormatter nameFormatter ,
30+ ILocalFunctions localFunctions ,
3031 CancellationToken cancellationToken )
3132 : IBuilder < RootContext , VarInjection >
3233{
@@ -102,25 +103,21 @@ private void BuildCode(CodeContext parentCtx)
102103
103104 var varsMap = varCtx . VarsMap ;
104105 var setup = varCtx . RootContext . Graph . Source ;
105- var isBlock = IsBlock ( var . AbstractNode ) ;
106- var isLazy = nodeInfo . IsLazy ( var . AbstractNode . Node ) ;
106+ var isBlock = nodeTools . IsBlock ( var . AbstractNode ) ;
107+ var isLazy = nodeTools . IsLazy ( var . AbstractNode . Node ) ;
107108 var . HasCycle ??= IsCycle ( varCtx . RootContext . Graph . Graph , var . Declaration . Node . Node , ImmutableHashSet < DependencyNode > . Empty ) ;
108109 var acc = isLazy ? accumulators . GetAccumulators ( varCtx . RootContext . Graph . Graph , var . AbstractNode ) . ToImmutableArray ( ) : ImmutableArray < ( MdAccumulator , Dependency ) > . Empty ;
109- var useLocalFunction = isBlock
110- && ! varCtx . HasOverrides
111- && varCtx . Accumulators . Length == 0
112- && varCtx . RootContext . Graph . Graph . TryGetOutEdges ( var . Declaration . Node . Node , out var targets ) && targets . Count > 1 ;
113-
110+ var isLocalFunction = localFunctions . UseFor ( varCtx ) ;
114111 var mapToken =
115- useLocalFunction
112+ isLocalFunction
116113 ? varsMap . LocalFunction ( var , lines )
117114 : isLazy
118115 ? varsMap . Lazy ( var , lines )
119116 : isBlock
120117 ? varsMap . Block ( var , lines )
121118 : Disposables . Empty ;
122119
123- if ( useLocalFunction || isLazy )
120+ if ( isLocalFunction || isLazy )
124121 {
125122 varCtx = varCtx with { IsLockRequired = varCtx . RootContext . IsThreadSafeEnabled } ;
126123 }
@@ -299,7 +296,7 @@ private void BuildCode(CodeContext parentCtx)
299296 {
300297 ExpressionSyntax ? value = null ;
301298 var type = memberResolver . ContractType ;
302- ExpressionSyntax instance = member . IsStatic
299+ var instance = member . IsStatic
303300 ? SyntaxFactory . ParseTypeName ( symbolNames . GetGlobalName ( type ) )
304301 : SyntaxFactory . IdentifierName ( Names . DefaultInstanceValueName ) ;
305302
@@ -735,7 +732,7 @@ private void BuildCode(CodeContext parentCtx)
735732
736733 mapToken . Dispose ( ) ;
737734
738- if ( useLocalFunction )
735+ if ( isLocalFunction )
739736 {
740737 var baseName = nameFormatter . Format ( "{type}{tag}" , varCtx . VarInjection . Var . InstanceType , varCtx . VarInjection . Injection . Tag ) ;
741738 var localFunction = var . LocalFunction ;
@@ -811,8 +808,6 @@ private static int GetInjectionPriority(VarInjection varInjection)
811808 return int . MaxValue ;
812809 }
813810
814- private static bool IsBlock ( IDependencyNode node ) => node . Lifetime is Singleton or Scoped or PerResolve ;
815-
816811 private void StartSingleInstanceCheck ( CodeContext ctx )
817812 {
818813 var isLockRequired = ctx . IsLockRequired ;
@@ -840,7 +835,7 @@ private void FinishSingleInstanceCheck(CodeContext ctx)
840835 {
841836 var var = ctx . VarInjection . Var ;
842837 var lines = ctx . Lines ;
843- if ( var . AbstractNode . Lifetime is Singleton or Scoped && nodeInfo . IsDisposableAny ( var . AbstractNode . Node ) )
838+ if ( var . AbstractNode . Lifetime is Singleton or Scoped && nodeTools . IsDisposableAny ( var . AbstractNode . Node ) )
844839 {
845840 var parent = "" ;
846841 if ( var . AbstractNode . Lifetime == Singleton )
0 commit comments