예제 #1
0
파일: ZenjectMenu.cs 프로젝트: vizkidd/MMO
        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);
                }
            }
        }
예제 #2
0
        public static IEnumerable <ZenjectResolveException> ValidateInstallers(CompositionRoot compRoot)
        {
            var globalContainer = GlobalCompositionRoot.CreateContainer(true, null);
            var container       = compRoot.CreateContainer(true, globalContainer);

            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 curTransform in compRoot.GetComponentsInChildren <Transform>())
            {
                foreach (var monoBehaviour in curTransform.GetComponents <MonoBehaviour>())
                {
                    if (monoBehaviour == null)
                    {
                        Log.Warn("Found null MonoBehaviour on " + curTransform.name);
                        continue;
                    }

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

            foreach (var installer in globalContainer.InstalledInstallers.Concat(container.InstalledInstallers))
            {
                if (installer is IValidatable)
                {
                    foreach (var error in ((IValidatable)installer).Validate())
                    {
                        yield return(error);
                    }
                }
            }

            foreach (var error in container.ValidateValidatables())
            {
                yield return(error);
            }
        }
예제 #3
0
        static IEnumerable <ZenjectResolveException> ValidateInstallers(CompositionRoot compRoot)
        {
            var container = new DiContainer();

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

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

                    yield break;
                }

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

            foreach (var error in ZenUtil.ValidateInstallers(container))
            {
                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
                    Debug.LogWarning("Found null MonoBehaviour in scene");
                    continue;
                }

                foreach (var error in container.ValidateObjectGraph(monoBehaviour.GetType()))
                {
                    yield return(error);
                }
            }
        }
예제 #4
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;
                }
            }
        }