Skip to content

Commit 93c3b25

Browse files
author
maximv
committed
small improvemtn for the WaitForItemIsSet
1 parent 260e7f3 commit 93c3b25

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/DryIoc/Container.cs

+15-14
Original file line numberDiff line numberDiff line change
@@ -9893,10 +9893,7 @@ cacheEntry.Value.ScopeNameOrDependencyCount is Container.Registry.TransientDepen
98939893

98949894
// Next, lookup for the already created service in the singleton scope
98959895
Expression serviceExpr;
9896-
if (request.Reuse is SingletonReuse &&
9897-
request.Rules.EagerCachingSingletonForFasterAccess
9898-
// && !request.IsWrappedInFunc() -- see the Note below for the reasons why it is commented out
9899-
)
9896+
if (request.Reuse is SingletonReuse && request.Rules.EagerCachingSingletonForFasterAccess)
99009897
{
99019898
// Then optimize for already resolved singleton object, otherwise goes normal ApplyReuse route
99029899
var id = request.FactoryType == FactoryType.Decorator
@@ -9913,16 +9910,22 @@ cacheEntry.Value.ScopeNameOrDependencyCount is Container.Registry.TransientDepen
99139910
//
99149911
// `class Singleton { public Singleton(Func<Singleton> fs) {} }`
99159912
//
9916-
// In this situation the `itemRef` will be creating but will stuck forever on the `WaitForItemIsSet` below.
9917-
// So the way-out here is to abondon the attempt to wait for the item and proceed to normal Expression creation.
9913+
// In this situation the `itemRef` will stuck forever on the `WaitForItemIsSet` below.
9914+
// So the way-out here is to abondon the attempt to wait for the item if we are not in the Func
9915+
// and proceed to the normal Expression creation.
99189916
//
9917+
if (itemRef.Value == Scope.NoItem)
9918+
{
9919+
if (!request.TracksTransientDisposable && !request.IsWrappedInFunc())
9920+
Scope.WaitForItemIsSet(itemRef);
9921+
}
9922+
99199923
if (itemRef.Value != Scope.NoItem) // get the item if and only if it is already created
99209924
{
99219925
var singleton = itemRef.Value;
9922-
serviceExpr = singleton == null
9923-
? Constant(null, request.GetActualServiceType()) // fixes #258
9924-
: Constant(singleton);
9925-
9926+
serviceExpr = singleton != null ? Constant(singleton)
9927+
: Constant(null, request.GetActualServiceType()); // fixes #258
9928+
99269929
if (Setup.WeaklyReferenced) // Unwrap WeakReference or HiddenDisposable in that order!
99279930
serviceExpr = Call(ThrowInGeneratedCode.WeakRefReuseWrapperGCedMethod,
99289931
Property(Convert(serviceExpr, typeof(WeakReference)), ThrowInGeneratedCode.WeakReferenceValueProperty));
@@ -10003,10 +10006,8 @@ protected virtual Expression ApplyReuse(Expression serviceExpr, Request request)
1000310006
// This optimization eagerly creates singleton during the construction of object graph
1000410007
// Singleton is created once and then is stred for the container lifetime (until Сontainer.SingletonScope is disposed).
1000510008
// That's why we are always intepreting them even if `Rules.WithoutInterpretationForTheFirstResolution()` is set.
10006-
if (request.Reuse is SingletonReuse &&
10007-
request.Rules.EagerCachingSingletonForFasterAccess &&
10008-
!request.TracksTransientDisposable &&
10009-
!request.IsWrappedInFunc())
10009+
if (request.Reuse is SingletonReuse && request.Rules.EagerCachingSingletonForFasterAccess &&
10010+
!request.TracksTransientDisposable && !request.IsWrappedInFunc())
1001010011
{
1001110012
var container = request.Container;
1001210013
var scope = (Scope)container.SingletonScope;

0 commit comments

Comments
 (0)