当前位置: 首页>>代码示例>>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;未经允许,请勿转载。