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


C# DiContainer.CreateSubContainer方法代碼示例

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


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

示例1: TestLocal1

        public void TestLocal1()
        {
            var rootContainer = new DiContainer();
            var sub1 = rootContainer.CreateSubContainer();

            rootContainer.Bind<Test0>().AsSingle();
            sub1.Bind<Test1>().AsSingle();

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

示例2: TestAny

        public void TestAny()
        {
            var rootContainer = new DiContainer();
            var sub1 = rootContainer.CreateSubContainer();

            rootContainer.Bind<Test0>().AsSingle();
            sub1.Bind<Test4>().AsSingle();

            Assert.IsNotNull(sub1.Resolve<Test4>());
        }
開發者ID:Soren025,項目名稱:Zenject,代碼行數:10,代碼來源:TestInjectSources.cs

示例3: TestLocal1

        public void TestLocal1()
        {
            var rootContainer = new DiContainer();
            var sub1 = rootContainer.CreateSubContainer();

            rootContainer.Bind<Test0>().ToSingle();
            sub1.Bind<Test1>().ToSingle();

            Assert.Throws<ZenjectResolveException>(() => sub1.Resolve<Test1>());
            Assert.That(sub1.ValidateResolve<Test1>().Any());
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:11,代碼來源:TestInjectSources.cs

示例4: Test1

        public void Test1()
        {
            DiContainer parentContainer = new DiContainer();
            parentContainer.Bind<Foo>().ToTransient();

            // ToTransient should always use the DiContainer given by the inject context
            var subContainer = parentContainer.CreateSubContainer();
            subContainer.Bind<int>().ToInstance<int>(5);

            var foo = subContainer.Resolve<Foo>();
            Assert.AreEqual(foo.Value, 5);
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:12,代碼來源:TestSubContainer3.cs

示例5: 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

示例6: 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

示例7: 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

示例8: TestParent2

        public void TestParent2()
        {
            var rootContainer = new DiContainer();
            var sub1 = rootContainer.CreateSubContainer();
            var sub2 = sub1.CreateSubContainer();

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

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

示例9: TestLocal2

        public void TestLocal2()
        {
            var rootContainer = new DiContainer();
            var sub1 = rootContainer.CreateSubContainer();

            sub1.Bind<Test0>().ToSingle();
            sub1.Bind<Test1>().ToSingle();

            Assert.IsNotNull(sub1.Resolve<Test1>());
            Assert.That(sub1.ValidateResolve<Test1>().IsEmpty());
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:11,代碼來源:TestInjectSources.cs

示例10: TestParentAny1

        public void TestParentAny1()
        {
            var rootContainer = new DiContainer();
            var sub1 = rootContainer.CreateSubContainer();
            var sub2 = sub1.CreateSubContainer();

            rootContainer.Bind<Test0>().ToSingle();
            sub2.Bind<Test3>().ToSingle();

            Assert.IsNotNull(sub2.Resolve<Test3>());
            Assert.That(sub2.ValidateResolve<Test3>().IsEmpty());
        }
開發者ID:Aszan,項目名稱:Zenject,代碼行數:12,代碼來源:TestInjectSources.cs


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