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


C# DiContainer.Resolve方法代碼示例

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


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

示例1: Test1

        public void Test1()
        {
            NumInstalls = 0;
            InitTest.WasRun = false;
            TickTest.WasRun = false;
            DisposeTest.WasRun = false;

            var container = new DiContainer();

            container.Bind(typeof(TickableManager), typeof(InitializableManager), typeof(DisposableManager))
                .ToSelf().AsSingle().InheritInSubContainers();

            // This is how you add ITickables / etc. within sub containers
            container.BindAllInterfacesAndSelf<FooKernel>()
                .To<FooKernel>().FromSubContainerResolve().ByMethod(InstallFoo).AsSingle();

            var tickManager = container.Resolve<TickableManager>();
            var initManager = container.Resolve<InitializableManager>();
            var disposeManager = container.Resolve<DisposableManager>();

            Assert.That(!InitTest.WasRun);
            Assert.That(!TickTest.WasRun);
            Assert.That(!DisposeTest.WasRun);

            initManager.Initialize();
            tickManager.Update();
            disposeManager.Dispose();

            Assert.That(InitTest.WasRun);
            Assert.That(TickTest.WasRun);
            Assert.That(DisposeTest.WasRun);
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:32,代碼來源:TestFacadeSubContainer.cs

示例2: TestBindAllInterfacesSimple

        public void TestBindAllInterfacesSimple()
        {
            var container = new DiContainer();

            container.Bind(x => x.AllInterfaces()).To<Foo>();

            Assert.That(container.Resolve<IFoo>() is Foo);
            Assert.That(container.Resolve<IBar>() is Foo);
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:9,代碼來源:TestConvention2.cs

示例3: RebindingInSubContainer

        public void RebindingInSubContainer()
        {
            DiContainer parentContainer = new DiContainer();
            parentContainer.Bind<IHaveMessage>().ToSingle<Welcome>();

            Assert.AreEqual("Welcome", parentContainer.Resolve<IHaveMessage>().GetMessage());

            DiContainer childContainer = parentContainer.CreateSubContainer();
            childContainer.Rebind<IHaveMessage>().ToSingle<Bye>();

            Assert.AreEqual("Bye", childContainer.Resolve<IHaveMessage>().GetMessage());

            Assert.AreEqual("Welcome", parentContainer.Resolve<IHaveMessage>().GetMessage());
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:14,代碼來源:TestSubContainer2.cs

示例4: Awake

        public void Awake()
        {
            var extraInstallers = new List<IInstaller>();

            if (_staticSettings != null)
            // Static settings are needed if creating a SceneCompositionRoot dynamically
            {
                extraInstallers = _staticSettings.Installers;
                OnlyInjectWhenActive = _staticSettings.OnlyInjectWhenActive;
                ParentNewObjectsUnderRoot = _staticSettings.ParentNewObjectsUnderRoot;
                _staticSettings = null;
            }

            // We always want to initialize GlobalCompositionRoot as early as possible
            GlobalCompositionRoot.Instance.EnsureIsInitialized();

            Assert.IsNull(Container);
            Assert.IsNull(RootFacade);

            Log.Debug("Initializing SceneCompositionRoot in scene '{0}'", this.gameObject.scene.name);
            _container = CreateContainer(
                false, GlobalCompositionRoot.Instance.Container, extraInstallers);

            Log.Debug("SceneCompositionRoot: Finished install phase.  Injecting into scene...");
            InjectObjectsInScene();

            Log.Debug("SceneCompositionRoot: Resolving root IFacade...");
            _rootFacade = _container.Resolve<IFacade>();

            DecoratedScenes.Clear();

            Assert.IsNotNull(Container);
            Assert.IsNotNull(RootFacade);
        }
開發者ID:terrehbyte,項目名稱:RitualNow,代碼行數:34,代碼來源:SceneCompositionRoot.cs

示例5: Initialize

        protected override void Initialize()
        {
            DontDestroyOnLoad(gameObject);

            // Is this a good idea?
            //go.hideFlags = HideFlags.HideInHierarchy;

            _container = CreateContainer(false, this);
            _rootFacade = _container.Resolve<IFacade>();
        }
開發者ID:4xisblack,項目名稱:Zenject,代碼行數:10,代碼來源:GlobalCompositionRoot.cs

示例6: Awake

        public void Awake()
        {
            DontDestroyOnLoad(gameObject);

            // Is this a good idea?
            //go.hideFlags = HideFlags.HideInHierarchy;

            _container = CreateContainer(false, gameObject);
            _dependencyRoot = _container.Resolve<IDependencyRoot>();
        }
開發者ID:IllusiveS,項目名稱:Asteroids,代碼行數:10,代碼來源:GlobalCompositionRoot.cs

示例7: AddPreBindings

        public void AddPreBindings(DiContainer container)
        {
            // Make our scene graph a child of the new CompositionRoot so any monobehaviour's that are
            // built into the scene get injected
            transform.parent = container.Resolve<CompositionRoot>().transform;

            CompositionRootHelper.InstallSceneInstallers(container, PreInstallers);

            ProcessDecoratorInstallers(container, true);
        }
開發者ID:IllusiveS,項目名稱:Asteroids,代碼行數:10,代碼來源:SceneDecoratorCompositionRoot.cs

示例8: TestCase1

        public void TestCase1()
        {
            var container1 = new DiContainer();

            Assert.Throws<ZenjectResolveException>(() => container1.Resolve<IFoo>());
            Assert.Throws<ZenjectResolveException>(() => Container.Resolve<IFoo>());

            Container.Bind<IFoo>().ToSingle<Foo>();

            Assert.Throws<ZenjectResolveException>(() => container1.Resolve<IFoo>());
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);

            var container2 = new DiContainer(Container);

            Assert.IsEqual(container2.Resolve<IFoo>().GetBar(), 0);
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);

            container2.Bind<IFoo>().ToSingle<Foo2>();

            Assert.IsEqual(container2.Resolve<IFoo>().GetBar(), 1);
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:22,代碼來源:TestNestedContainer.cs

示例9: TestCase1

        public void TestCase1()
        {
            var nestedContainer = new DiContainer();

            Assert.Throws<ZenjectResolveException>(() => nestedContainer.Resolve<IFoo>());
            Assert.Throws<ZenjectResolveException>(() => Container.Resolve<IFoo>());

            Container.Bind<IFoo>().ToSingle<Foo>();

            Assert.Throws<ZenjectResolveException>(() => nestedContainer.Resolve<IFoo>());
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);

            nestedContainer.FallbackProvider = new DiContainerProvider(Container);

            Assert.IsEqual(nestedContainer.Resolve<IFoo>().GetBar(), 0);
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);

            nestedContainer.Bind<IFoo>().ToSingle<Foo2>();

            Assert.IsEqual(nestedContainer.Resolve<IFoo>().GetBar(), 1);
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);
        }
開發者ID:RainsSoft,項目名稱:Zenject,代碼行數:22,代碼來源:TestNestedContainer.cs

示例10: TestCase1

        public void TestCase1()
        {
            var container1 = new DiContainer();

            Assert.Throws(() => container1.Resolve<IFoo>());
            Assert.Throws(() => Container.Resolve<IFoo>());

            Container.Bind<IFoo>().To<Foo>().AsSingle();

            Assert.Throws(() => container1.Resolve<IFoo>());
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);

            var container2 = Container.CreateSubContainer();

            Assert.IsEqual(container2.Resolve<IFoo>().GetBar(), 0);
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);

            container2.Bind<IFoo>().To<Foo2>().AsSingle();

            Assert.IsEqual(container2.Resolve<IFoo>().GetBar(), 1);
            Assert.IsEqual(Container.Resolve<IFoo>().GetBar(), 0);
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:22,代碼來源:TestNestedContainer.cs

示例11: Initialize

        void Initialize()
        {
            Log.Debug("Initializing GlobalCompositionRoot");

            Assert.IsNull(Container);
            Assert.IsNull(RootFacade);

            DontDestroyOnLoad(gameObject);

            _container = CreateContainer(false, this);
            _rootFacade = _container.Resolve<IFacade>();

            Assert.IsNotNull(Container);
            Assert.IsNotNull(RootFacade);
        }
開發者ID:terrehbyte,項目名稱:RitualNow,代碼行數:15,代碼來源:GlobalCompositionRoot.cs

示例12: RebindingInSubContainer2

        public void RebindingInSubContainer2()
        {
            DiContainer parentContainer = new DiContainer();
            parentContainer.Bind<IHaveMessage>().ToSingle<Welcome>();

            Assert.AreEqual("Welcome", parentContainer.Resolve<IHaveMessage>().GetMessage());

            DiContainer childContainer = parentContainer.CreateSubContainer();
            User user = new User();
            childContainer.Inject(user);

            Assert.AreEqual("Welcome", user.SayIt());
            user.Rebind();
            Assert.AreEqual("Bye", user.SayIt());

            parentContainer.Inject(user);
            Assert.AreEqual("Welcome", user.SayIt());
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:18,代碼來源:TestSubContainer2.cs

示例13: Awake

        public void Awake()
        {
            _container = CreateContainer(
                false, GlobalCompositionRoot.Instance.Container, _staticInstallers);
            _staticInstallers.Clear();

            if (InjectFullScene)
            {
                var rootGameObjects = GameObject.FindObjectsOfType<Transform>()
                    .Where(x => x.parent == null && x.GetComponent<GlobalCompositionRoot>() == null && (x.GetComponent<CompositionRoot>() == null || x == this.transform))
                    .Select(x => x.gameObject).ToList();

                foreach (var rootObj in rootGameObjects)
                {
                    _container.InjectGameObject(rootObj, true, !OnlyInjectWhenActive);
                }
            }
            else
            {
                _container.InjectGameObject(gameObject, true, !OnlyInjectWhenActive);
            }

            _dependencyRoot = _container.Resolve<IDependencyRoot>();
        }
開發者ID:zeljkokalezic,項目名稱:Reactive-Space-Shooter,代碼行數:24,代碼來源:CompositionRoot.cs

示例14: TestParent3

        public void TestParent3()
        {
            var rootContainer = new DiContainer();

            rootContainer.Bind<Test0>().AsSingle();
            rootContainer.Bind<Test2>().AsSingle();

            Assert.Throws(() => rootContainer.Resolve<Test2>());
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:9,代碼來源:TestInjectSources.cs

示例15: TestValidateNestedContainerList

        public void TestValidateNestedContainerList()
        {
            var container = new DiContainer();

            var nestedContainer = new DiContainer(container);

            container.Bind<IFoo>().ToSingle<Foo>();
            container.Bind<IFoo>().ToSingle<Foo2>();

            Assert.That(!container.ValidateResolve<List<IFoo>>().IsEmpty());
            Assert.That(!nestedContainer.ValidateResolve<List<IFoo>>().IsEmpty());

            container.Bind<Bar>().ToSingle();

            Assert.That(container.ValidateResolve<List<IFoo>>().IsEmpty());

            // Should not throw
            nestedContainer.Resolve<List<IFoo>>();

            Assert.That(nestedContainer.ValidateResolve<List<IFoo>>().IsEmpty());
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:21,代碼來源:TestValidateInstaller.cs


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