From cd81f3dd8da1e3545e46cc029e31d03572f9ecd3 Mon Sep 17 00:00:00 2001 From: dadhi Date: Sat, 26 Feb 2022 23:16:45 +0100 Subject: [PATCH] cleanup --- src/DryIoc/Container.cs | 31 +++++++------------------------ 1 file changed, 7 insertions(+), 24 deletions(-) diff --git a/src/DryIoc/Container.cs b/src/DryIoc/Container.cs index b82572eb..53c4abaf 100644 --- a/src/DryIoc/Container.cs +++ b/src/DryIoc/Container.cs @@ -5320,24 +5320,14 @@ public static Expression GetLazyExpressionOrDefault(Request request, bool nullWr { // Here we need to know if the lazy is resolvable, // by resolving the factory we are checking that the service itself is registered... + // But what about its dependencies. In order to check on them we need to get the expression, + // but avoid the creation of singletons on the way (and materializing the types) - because "lazy". + // Plus we need to stop on the encountering the root service because lazy permits a circular dependencies. + // See #449 for additional details var serviceFactory = container.ResolveFactory(serviceRequest); if (serviceFactory == null) return null; serviceRequest = serviceRequest.WithResolvedFactory(serviceFactory, skipRecursiveDependencyCheck: true); - - // But what about its dependencies. In order to check on them we need to get the expression, - // but avoid the creation of singletons on the way (and materializing the types) - because "lazy". - // Plus we need to stop on the encountering the root service because lazy permits a circular dependencies. - // The dependency check is the open question, see #449 - // todo: @wip - // if (!request.HasRecursiveParentUntilResolutionRoot(serviceFactory.FactoryID)) - // { - // serviceRequest.Flags |= RequestFlags.CheckTheRegistrationWithoutCreatingExpression; - // var expr = serviceFactory.GetExpressionOrDefault(serviceRequest); - // if (expr == null) - // return request.IfUnresolved == IfUnresolved.Throw ? null : Constant(null, lazyType); - // serviceRequest.Flags &= RequestFlags.CheckTheRegistrationWithoutCreatingExpression; - // } } // creates: r => new Lazy(() => r.Resolve(key)) @@ -9057,10 +9047,7 @@ public enum RequestFlags IsGeneratedResolutionDependencyExpression = 1 << 8, /// Non inherited. Indicates the root service inside the function. - IsDirectlyWrappedInFunc = 1 << 9, - - /// - CheckTheRegistrationWithoutCreatingExpression = 1 << 10 + IsDirectlyWrappedInFunc = 1 << 9 } /// Helper extension methods to use on the bunch of factories instead of lambdas to minimize allocations @@ -9123,8 +9110,7 @@ public sealed class Request : IEnumerable { internal static readonly RequestFlags InheritedFlags = RequestFlags.IsSingletonOrDependencyOfSingleton - | RequestFlags.IsWrappedInFunc - | RequestFlags.CheckTheRegistrationWithoutCreatingExpression; + | RequestFlags.IsWrappedInFunc; private const RequestFlags DefaultFlags = default; @@ -9276,8 +9262,6 @@ internal void DecreaseTrackedDependencyCountForParents(int dependencyCount) /// Checks if request has parent with service type of Func with arguments. public bool IsWrappedInFuncWithArgs() => InputArgExprs != null; - internal bool CheckTheRegistrationWithoutCreatingExpression() => (Flags & RequestFlags.CheckTheRegistrationWithoutCreatingExpression) != 0; - /// Returns expression for func arguments. public Expression GetInputArgsExpr() => InputArgExprs == null ? Constant(null, typeof(object[])) @@ -10459,8 +10443,7 @@ public virtual Expression GetExpressionOrDefault(Request request) Caching != FactoryCaching.DoNotCache && FactoryType == FactoryType.Service && !request.IsResolutionRoot && - (request.Flags & RequestFlags.CheckTheRegistrationWithoutCreatingExpression) == 0 && - !request.IsDirectlyWrappedInFunc() && + !request.IsDirectlyWrappedInFunc() && !request.IsWrappedInFuncWithArgs() && !(request.Reuse.Name is IScopeName) && !setup.AsResolutionCall && // see #295