Beispiel #1
0
        public static IEnumerable <ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot)
        {
            var globalContainer = GlobalCompositionRoot.CreateContainer(true, null);
            var container       = compRoot.CreateContainer(true, globalContainer, new List <IInstaller>());

            foreach (var error in container.ValidateResolve(new InjectContext(container, typeof(IDependencyRoot), null)))
            {
                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);
            }
        }
Beispiel #2
0
        public static IEnumerable<ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot)
        {
            var globalContainer = GlobalCompositionRoot.CreateContainer(true, null);
            var container = compRoot.CreateContainer(true, globalContainer, new List<IInstaller>());

            foreach (var error in container.ValidateResolve(new InjectContext(container, typeof(IFacade), null)))
            {
                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;
            }
        }