當前位置: 首頁>>代碼示例>>C#>>正文


C# DiContainer.ResolveDependencyRoots方法代碼示例

本文整理匯總了C#中Zenject.DiContainer.ResolveDependencyRoots方法的典型用法代碼示例。如果您正苦於以下問題:C# DiContainer.ResolveDependencyRoots方法的具體用法?C# DiContainer.ResolveDependencyRoots怎麽用?C# DiContainer.ResolveDependencyRoots使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zenject.DiContainer的用法示例。


在下文中一共展示了DiContainer.ResolveDependencyRoots方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Construct

        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");
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:41,代碼來源:GameObjectContext.cs

示例2: Initialize

        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());
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:45,代碼來源:ProjectContext.cs

示例3: RunInternal

        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");
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:59,代碼來源:SceneContext.cs


注:本文中的Zenject.DiContainer.ResolveDependencyRoots方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。