Beispiel #1
0
        public static IEnumerable <ZenjectResolveException> ValidateObjectGraph(
            DiContainer container, Type concreteType, params Type[] extras)
        {
            using (container.PushLookup(concreteType))
            {
                var typeInfo   = TypeAnalyzer.GetInfo(concreteType);
                var extrasList = extras.ToList();

                foreach (var dependInfo in typeInfo.AllInjectables)
                {
                    Assert.IsEqual(dependInfo.EnclosingType, concreteType);

                    if (TryTakingFromExtras(dependInfo.ContractType, extrasList))
                    {
                        continue;
                    }

                    var context = new InjectContext(
                        dependInfo, DiContainer.LookupsInProgress.ToList(), null);

                    foreach (var error in ValidateContract(
                                 container, dependInfo.ContractType, context))
                    {
                        yield return(error);
                    }
                }

                if (!extrasList.IsEmpty())
                {
                    yield return(new ZenjectResolveException(
                                     "Found unnecessary extra parameters passed when injecting into '{0}' with types '{1}'.  \nObject graph:\n{2}"
                                     .With(concreteType.Name(), String.Join(",", extrasList.Select(x => x.Name()).ToArray()), DiContainer.GetCurrentObjectGraph())));
                }
            }
        }
Beispiel #2
0
 public object Instantiate(
     Type concreteType, params object[] constructorArgs)
 {
     using (_container.PushLookup(concreteType))
     {
         return(InstantiateInternal(concreteType, constructorArgs));
     }
 }
Beispiel #3
0
 public object Instantiate(
     Type concreteType, params object[] constructorArgs)
 {
     using (ProfileBlock.Start("Zenject.Instantiate({0})".With(concreteType)))
     {
         using (_container.PushLookup(concreteType))
         {
             return(InstantiateInternal(concreteType, constructorArgs));
         }
     }
 }
Beispiel #4
0
 public object InstantiateExplicit(
     Type concreteType, List <TypeValuePair> extraArgMap)
 {
     using (ProfileBlock.Start("Zenject.Instantiate({0})", concreteType))
     {
         using (_container.PushLookup(concreteType))
         {
             return(InstantiateInternal(concreteType, extraArgMap));
         }
     }
 }
 public static void InjectMonoBehaviour(
     DiContainer container, MonoBehaviour monoBehaviour, IEnumerable <object> extraArgs)
 {
     // null if monobehaviour link is broken
     if (monoBehaviour != null && monoBehaviour.enabled)
     {
         using (container.PushLookup(monoBehaviour.GetType()))
         {
             FieldsInjecter.Inject(container, monoBehaviour, extraArgs);
         }
     }
 }
Beispiel #6
0
 public static void InjectMonoBehaviour(
     DiContainer container, Component component, IEnumerable <object> extraArgs)
 {
     // null if monobehaviour link is broken
     if (component != null)
     {
         using (container.PushLookup(component.GetType()))
         {
             FieldsInjecter.Inject(container, component, extraArgs);
         }
     }
 }