Ejemplo n.º 1
0
        static IEnumerable <ZenjectResolveException> ValidateInstallers(CompositionRoot compRoot)
        {
            var container = new DiContainer();

            container.Bind <CompositionRoot>().ToSingle(compRoot);

            var allInstallers = new List <IInstaller>();

            foreach (var installer in compRoot.Installers)
            {
                if (installer == null)
                {
                    yield return(new ZenjectResolveException(
                                     "Found null installer in properties of Composition Root"));

                    yield break;
                }

                if (installer.enabled)
                {
                    installer.Container = container;
                    container.Bind <IInstaller>().To(installer);
                }

                allInstallers.AddRange(container.InstallInstallers());

                Assert.That(!container.HasBinding <IInstaller>());
            }

            foreach (var error in container.ValidateResolve <IDependencyRoot>())
            {
                yield return(error);
            }

            // Also make sure we can fill in all the dependencies in the built-in scene
            foreach (var monoBehaviour in compRoot.GetComponentsInChildren <MonoBehaviour>())
            {
                if (monoBehaviour == null)
                {
                    // Be nice to give more information here
                    Log.Warn("Found null MonoBehaviour in scene");
                    continue;
                }

                foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType()))
                {
                    yield return(error);
                }
            }

            // Validate dynamically created object graphs
            foreach (var installer in allInstallers)
            {
                foreach (var error in installer.ValidateSubGraphs())
                {
                    yield return(error);
                }
            }
        }
Ejemplo n.º 2
0
        public static IEnumerable <ZenjectResolveException> ValidateInstallers(DiContainer container)
        {
            var allInstallers = InstallInstallers(container);

            foreach (var error in container.ValidateResolve <IDependencyRoot>())
            {
                yield return(error);
            }

            foreach (var installer in allInstallers)
            {
                foreach (var error in installer.ValidateSubGraphs())
                {
                    yield return(error);
                }
            }
        }
Ejemplo n.º 3
0
 public override IEnumerable <ZenjectResolveException> ValidateBinding(Type contractType, InjectContext context)
 {
     return(_container.ValidateResolve(contractType, context));
 }