Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
dadhi committed Feb 26, 2022
1 parent 1799e1e commit cd81f3d
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/DryIoc/Container.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<X>(key))
Expand Down Expand Up @@ -9057,10 +9047,7 @@ public enum RequestFlags
IsGeneratedResolutionDependencyExpression = 1 << 8,

/// <summary>Non inherited. Indicates the root service inside the function.</summary>
IsDirectlyWrappedInFunc = 1 << 9,

///<summary></summary>
CheckTheRegistrationWithoutCreatingExpression = 1 << 10
IsDirectlyWrappedInFunc = 1 << 9
}

/// Helper extension methods to use on the bunch of factories instead of lambdas to minimize allocations
Expand Down Expand Up @@ -9123,8 +9110,7 @@ public sealed class Request : IEnumerable<Request>
{
internal static readonly RequestFlags InheritedFlags
= RequestFlags.IsSingletonOrDependencyOfSingleton
| RequestFlags.IsWrappedInFunc
| RequestFlags.CheckTheRegistrationWithoutCreatingExpression;
| RequestFlags.IsWrappedInFunc;

private const RequestFlags DefaultFlags = default;

Expand Down Expand Up @@ -9276,8 +9262,6 @@ internal void DecreaseTrackedDependencyCountForParents(int dependencyCount)
/// <summary>Checks if request has parent with service type of Func with arguments.</summary>
public bool IsWrappedInFuncWithArgs() => InputArgExprs != null;

internal bool CheckTheRegistrationWithoutCreatingExpression() => (Flags & RequestFlags.CheckTheRegistrationWithoutCreatingExpression) != 0;

/// <summary>Returns expression for func arguments.</summary>
public Expression GetInputArgsExpr() =>
InputArgExprs == null ? Constant(null, typeof(object[]))
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit cd81f3d

Please sign in to comment.