Ejemplo n.º 1
0
 private InjectionPlan BuildClassNodeInjectionPlan(IClassNode cn,
                                                   object cachedInstance,
                                                   IClassNode externalConstructor,
                                                   IClassNode boundImpl,
                                                   IClassNode defaultImpl,
                                                   IDictionary <INode, InjectionPlan> memo)
 {
     if (cachedInstance != null)
     {
         return(new CsInstance(cn, cachedInstance));
     }
     else if (externalConstructor != null)
     {
         BuildInjectionPlan(externalConstructor, memo);
         InjectionPlan ip = null;
         memo.TryGetValue(externalConstructor, out ip);
         return(new Subplan(cn, 0, new InjectionPlan[] { ip }));
     }
     else if (boundImpl != null && !cn.Equals(boundImpl))
     {
         // We need to delegate to boundImpl, so recurse.
         BuildInjectionPlan(boundImpl, memo);
         InjectionPlan ip = null;
         memo.TryGetValue(boundImpl, out ip);
         return(new Subplan(cn, 0, new InjectionPlan[] { ip }));
     }
     else if (defaultImpl != null && !cn.Equals(defaultImpl))
     {
         BuildInjectionPlan(defaultImpl, memo);
         InjectionPlan ip = null;
         memo.TryGetValue(defaultImpl, out ip);
         return(new Subplan(cn, 0, new InjectionPlan[] { ip }));
     }
     else
     {
         // if we're here and there is a bound impl or a default impl,
         // then we're bound / defaulted to ourselves, so don't add
         // other impls to the list of things to consider.
         List <IClassNode> candidateImplementations = new List <IClassNode>();
         if (boundImpl == null && defaultImpl == null)
         {
             foreach (var ki in cn.GetKnownImplementations())
             {
                 candidateImplementations.Add(ki);
             }
         }
         candidateImplementations.Add(cn);
         List <InjectionPlan> sub_ips = FilterCandidateConstructors(candidateImplementations, memo);
         if (candidateImplementations.Count == 1 && candidateImplementations[0].GetFullName().Equals(cn.GetFullName()))
         {
             return(WrapInjectionPlans(cn, sub_ips, false, -1));
         }
         else
         {
             return(WrapInjectionPlans(cn, sub_ips, true, -1));
         }
     }
 }
Ejemplo n.º 2
0
 private InjectionPlan BuildClassNodeInjectionPlan(IClassNode cn,
     object cachedInstance,
     IClassNode externalConstructor, 
     IClassNode boundImpl,
     IClassNode defaultImpl,
     IDictionary<INode, InjectionPlan> memo)
 {
     if (cachedInstance != null)
     {
         return new CsInstance(cn, cachedInstance);
     }
     else if (externalConstructor != null)
     {
         BuildInjectionPlan(externalConstructor, memo);
         InjectionPlan ip = null;
         memo.TryGetValue(externalConstructor, out ip);
         return new Subplan(cn, 0, new InjectionPlan[] { ip });
     }
     else if (boundImpl != null && !cn.Equals(boundImpl))
     {
         // We need to delegate to boundImpl, so recurse.
         BuildInjectionPlan(boundImpl, memo);
         InjectionPlan ip = null;
         memo.TryGetValue(boundImpl, out ip);
         return new Subplan(cn, 0, new InjectionPlan[] { ip });
     }
     else if (defaultImpl != null && !cn.Equals(defaultImpl))
     {
         BuildInjectionPlan(defaultImpl, memo);
         InjectionPlan ip = null;
         memo.TryGetValue(defaultImpl, out ip);
         return new Subplan(cn, 0, new InjectionPlan[] { ip });
     }
     else {
         // if we're here and there is a bound impl or a default impl,
         // then we're bound / defaulted to ourselves, so don't add
         // other impls to the list of things to consider.
         List<IClassNode> candidateImplementations = new List<IClassNode>();
         if (boundImpl == null && defaultImpl == null)
         {
             foreach (var ki in cn.GetKnownImplementations())
             candidateImplementations.Add(ki);
         }
         candidateImplementations.Add(cn);
         List<InjectionPlan> sub_ips = FilterCandidateConstructors(candidateImplementations, memo);
         if (candidateImplementations.Count == 1 && candidateImplementations[0].GetFullName().Equals(cn.GetFullName()))
         {
             return WrapInjectionPlans(cn, sub_ips, false, -1);
         }
         else
         {
             return WrapInjectionPlans(cn, sub_ips, true, -1);
         }
     }
 }