コード例 #1
0
        public static IEnumerable <ZenjectResolveException> ValidateInstallers(SceneCompositionRoot compRoot, GameObject rootGameObject)
        {
            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);
            }

            var injectedGameObjects = rootGameObject != null?rootGameObject.GetComponentsInChildren <Transform>() : GameObject.FindObjectsOfType <Transform>();

            // Also make sure we can fill in all the dependencies in the built-in scene
            foreach (var curTransform in injectedGameObjects)
            {
                foreach (var monoBehaviour in curTransform.GetComponents <MonoBehaviour>())
                {
                    if (monoBehaviour == null)
                    {
                        // fiBackupSceneStorage shows up sometimes for reasons I don't understand
                        // but it's normal so ignore
                        if (curTransform.name != "fiBackupSceneStorage")
                        {
                            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).OfType <IValidatable>())
            {
                foreach (var error in installer.Validate())
                {
                    yield return(error);
                }
            }

            foreach (var error in container.ValidateValidatables())
            {
                yield return(error);
            }
        }
コード例 #2
0
        public static DiContainer CreateContainer(bool allowNullBindings, GlobalCompositionRoot root)
        {
            Assert.That(allowNullBindings || root != null);

            var container = new DiContainer(root == null ? null : root.transform);

            container.AllowNullBindings = allowNullBindings;

            container.Bind<GlobalCompositionRoot>().ToInstance(root);
            container.Bind<CompositionRoot>().ToInstance(root);

            container.Install<StandardInstaller>();

            container.Install(GetGlobalInstallers());

            return container;
        }
コード例 #3
0
        public static DiContainer CreateContainer(bool allowNullBindings, GlobalCompositionRoot root)
        {
            Assert.That(allowNullBindings || root != null);

            var container = new DiContainer(root == null ? null : root.transform);

            container.AllowNullBindings = allowNullBindings;

            container.Bind <GlobalCompositionRoot>().ToInstance(root);
            container.Bind <CompositionRoot>().ToInstance(root);

            container.Install <StandardUnityInstaller>();

            CompositionRootHelper.InstallSceneInstallers(container, GetGlobalInstallers());

            return(container);
        }
コード例 #4
0
        public static DiContainer CreateContainer(bool isValidating, GlobalCompositionRoot root)
        {
            Assert.That(isValidating || root != null);

            var container = new DiContainer(root == null ? null : root.transform);

            container.IsValidating = isValidating;

            container.Bind <GlobalCompositionRoot>().ToInstance(root);
            container.Bind <CompositionRoot>().ToInstance(root);

            container.Install <StandardInstaller>();

            container.Install(GetGlobalInstallers());

            return(container);
        }
コード例 #5
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);
            }
        }
コード例 #6
0
        public static DiContainer CreateContainer(bool isValidating, GlobalCompositionRoot root)
        {
            Assert.That(isValidating || root != null);

            var container = new DiContainer();

            container.IsValidating = isValidating;

            if (root != null)
            {
                container.Bind <Transform>(ZenConstants.DefaultParentId)
                .ToInstance <Transform>(root.gameObject.transform);
            }

            container.Bind <CompositionRoot>().ToInstance(root);
            container.Bind <GlobalCompositionRoot>().ToInstance(root);

            container.Install <StandardInstaller>();
            container.Install(GetGlobalInstallers());

            return(container);
        }
コード例 #7
0
        public static DiContainer CreateContainer(bool isValidating, GlobalCompositionRoot root)
        {
            Assert.That(isValidating || root != null);

            var container = new DiContainer();

            container.IsValidating = isValidating;

            if (root != null)
            {
                container.Bind<Transform>(ZenConstants.DefaultParentId)
                    .ToInstance<Transform>(root.gameObject.transform);
            }

            container.Bind<CompositionRoot>().ToInstance(root);
            container.Bind<GlobalCompositionRoot>().ToInstance(root);

            container.Install<StandardInstaller>();
            container.Install(GetGlobalInstallers());

            return container;
        }
コード例 #8
0
 // If we're destroyed manually somehow handle that
 public void OnDestroy()
 {
     _instance = null;
     _dependencyRoot = null;
 }
コード例 #9
0
 // If we're destroyed manually somehow handle that
 public void OnDestroy()
 {
     _instance       = null;
     _dependencyRoot = null;
 }