Example #1
0
        public void RunInternal()
        {
            Assert.That(!_hasInitialized);
            _hasInitialized = true;

            Assert.IsNull(_container);

            var parentContainer = ParentContainer ?? ProjectContext.Instance.Container;

            // ParentContainer is optionally set temporarily before calling ZenUtil.LoadScene
            ParentContainer = null;

            _container = parentContainer.CreateSubContainer(IsValidating);

#if !UNITY_EDITOR
            Assert.That(!IsValidating);
#endif

            // This can happen if you run a decorated scene with immediately running a normal scene afterwards
            foreach (var decoratedScene in DecoratedScenes)
            {
                Assert.That(decoratedScene.isLoaded,
                            "Unexpected state in SceneContext - found unloaded decorated scene");
            }

            // Record all the injectable components in the scene BEFORE installing the installers
            // This is nice for cases where the user calls InstantiatePrefab<>, etc. in their installer
            // so that it doesn't inject on the game object twice
            // InitialComponentsInjecter will also guarantee that any component that is injected into
            // another component has itself been injected
            var componentInjecter = new InitialComponentsInjecter(
                _container, GetInjectableComponents().ToList());

            Log.Debug("SceneContext: Running installers...");

            _container.IsInstalling = true;

            try
            {
                InstallBindings(componentInjecter);
            }
            finally
            {
                _container.IsInstalling = false;
            }

            Log.Debug("SceneContext: Injecting components in the scene...");

            componentInjecter.LazyInjectComponents();

            Log.Debug("SceneContext: Resolving dependency roots...");

            Assert.That(_dependencyRoots.IsEmpty());
            _dependencyRoots.AddRange(_container.ResolveDependencyRoots());

            DecoratedScenes.Clear();

            Log.Debug("SceneContext: Initialized successfully");
        }
        void Initialize()
        {
            Log.Debug("Initializing ProjectContext");

            Assert.IsNull(_container);

            DontDestroyOnLoad(gameObject);

            bool isValidating = false;

#if UNITY_EDITOR
            isValidating = PersistentIsValidating;

            if (isValidating)
            {
                ValidationSceneDisabler.Instance.DisableEverything();
            }

            // Always default to false to avoid validating next time play is hit
            PersistentIsValidating = false;
#endif

            _container = new DiContainer(
                StaticContext.Container, isValidating);

            var componentInjecter = new InitialComponentsInjecter(
                _container, GetInjectableComponents().ToList());

            _container.IsInstalling = true;

            try
            {
                InstallBindings(componentInjecter);
            }
            finally
            {
                _container.IsInstalling = false;
            }

            componentInjecter.LazyInjectComponents();

            Assert.That(_dependencyRoots.IsEmpty());

            _dependencyRoots.AddRange(_container.ResolveDependencyRoots());
        }
Example #3
0
        public void Construct(
            DiContainer parentContainer,
            [InjectOptional]
            InstallerExtraArgs installerExtraArgs)
        {
            Assert.IsNull(_container);

            _container = parentContainer.CreateSubContainer();

            var componentInjecter = new InitialComponentsInjecter(
                _container, GetInjectableComponents().ToList());

            foreach (var component in componentInjecter.Components)
            {
                if (component is MonoKernel)
                {
                    Assert.That(component == _kernel,
                                "Found MonoKernel derived class that is not hooked up to GameObjectContext.  If you use MonoKernel, you must indicate this to GameObjectContext by dragging and dropping it to the Kernel field in the inspector");
                }
            }

            _container.IsInstalling = true;

            try
            {
                InstallBindings(installerExtraArgs, componentInjecter);
            }
            finally
            {
                _container.IsInstalling = false;
            }

            Log.Debug("GameObjectContext: Injecting into child components...");

            componentInjecter.LazyInjectComponents();

            Assert.That(_dependencyRoots.IsEmpty());
            _dependencyRoots.AddRange(_container.ResolveDependencyRoots());

            Log.Debug("GameObjectContext: Initialized successfully");
        }
Example #4
0
        public void Construct(
            DiContainer parentContainer,
            [InjectOptional]
            InstallerExtraArgs installerExtraArgs)
        {
            Assert.IsNull(_container);

            _container = parentContainer.CreateSubContainer();

            var componentInjecter = new InitialComponentsInjecter(
                _container, GetInjectableComponents().ToList());

            foreach (var component in componentInjecter.Components)
            {
                if (component is MonoKernel)
                {
                    Assert.That(component == _kernel,
                        "Found MonoKernel derived class that is not hooked up to GameObjectContext.  If you use MonoKernel, you must indicate this to GameObjectContext by dragging and dropping it to the Kernel field in the inspector");
                }
            }

            _container.IsInstalling = true;

            try
            {
                InstallBindings(installerExtraArgs, componentInjecter);
            }
            finally
            {
                _container.IsInstalling = false;
            }

            Log.Debug("GameObjectContext: Injecting into child components...");

            componentInjecter.LazyInjectComponents();

            Assert.That(_dependencyRoots.IsEmpty());
            _dependencyRoots.AddRange(_container.ResolveDependencyRoots());

            Log.Debug("GameObjectContext: Initialized successfully");
        }
Example #5
0
        void Initialize()
        {
            Log.Debug("Initializing ProjectContext");

            Assert.IsNull(_container);

            DontDestroyOnLoad(gameObject);

            bool isValidating = false;

#if UNITY_EDITOR
            isValidating = PersistentIsValidating;

            if (isValidating)
            {
                ValidationSceneDisabler.Instance.DisableEverything();
            }

            // Always default to false to avoid validating next time play is hit
            PersistentIsValidating = false;
#endif

            _container = new DiContainer(
                StaticContext.Container, isValidating);

            var componentInjecter = new InitialComponentsInjecter(
                _container, GetInjectableComponents().ToList());

            _container.IsInstalling = true;

            try
            {
                InstallBindings(componentInjecter);
            }
            finally
            {
                _container.IsInstalling = false;
            }

            componentInjecter.LazyInjectComponents();

            Assert.That(_dependencyRoots.IsEmpty());

            _dependencyRoots.AddRange(_container.ResolveDependencyRoots());
        }
Example #6
0
        public void RunInternal()
        {
            Assert.That(!_hasInitialized);
            _hasInitialized = true;

            Assert.IsNull(_container);

            var parentContainer = ParentContainer ?? ProjectContext.Instance.Container;

            // ParentContainer is optionally set temporarily before calling ZenUtil.LoadScene
            ParentContainer = null;

            _container = parentContainer.CreateSubContainer(IsValidating);

#if !UNITY_EDITOR
            Assert.That(!IsValidating);
#endif

            // This can happen if you run a decorated scene with immediately running a normal scene afterwards
            foreach (var decoratedScene in DecoratedScenes)
            {
                Assert.That(decoratedScene.isLoaded,
                    "Unexpected state in SceneContext - found unloaded decorated scene");
            }

            // Record all the injectable components in the scene BEFORE installing the installers
            // This is nice for cases where the user calls InstantiatePrefab<>, etc. in their installer
            // so that it doesn't inject on the game object twice
            // InitialComponentsInjecter will also guarantee that any component that is injected into
            // another component has itself been injected
            var componentInjecter = new InitialComponentsInjecter(
                _container, GetInjectableComponents().ToList());

            Log.Debug("SceneContext: Running installers...");

            _container.IsInstalling = true;

            try
            {
                InstallBindings(componentInjecter);
            }
            finally
            {
                _container.IsInstalling = false;
            }

            Log.Debug("SceneContext: Injecting components in the scene...");

            componentInjecter.LazyInjectComponents();

            Log.Debug("SceneContext: Resolving dependency roots...");

            Assert.That(_dependencyRoots.IsEmpty());
            _dependencyRoots.AddRange(_container.ResolveDependencyRoots());

            DecoratedScenes.Clear();

            Log.Debug("SceneContext: Initialized successfully");
        }