当前位置: 首页>>代码示例>>C#>>正文


C# DiContainer.Bind方法代码示例

本文整理汇总了C#中Zenject.DiContainer.Bind方法的典型用法代码示例。如果您正苦于以下问题:C# DiContainer.Bind方法的具体用法?C# DiContainer.Bind怎么用?C# DiContainer.Bind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zenject.DiContainer的用法示例。


在下文中一共展示了DiContainer.Bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBasicSuccess

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

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

            Assert.That(container.ValidateResolve<IFoo>().IsEmpty());
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:9,代码来源:TestValidateInstaller.cs

示例2: InstallFoo

        public void InstallFoo(DiContainer subContainer)
        {
            NumInstalls++;

            subContainer.Bind<FooKernel>().AsSingle();

            subContainer.Bind<IInitializable>().To<InitTest>().AsSingle();
            subContainer.Bind<ITickable>().To<TickTest>().AsSingle();
            subContainer.Bind<IDisposable>().To<DisposeTest>().AsSingle();
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:10,代码来源:TestFacadeSubContainer.cs

示例3: TestList

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

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

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

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

            Assert.That(container.ValidateResolve<Qux>().IsEmpty());
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:13,代码来源:TestValidateInstaller.cs

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

示例5: CreateContainer

        public static DiContainer CreateContainer(bool allowNullBindings, GlobalCompositionRoot root)
        {
            Assert.That(allowNullBindings || root != null);

            var container = new DiContainer(root == null ? null : root.transform);

            container.AllowNullBindings = allowNullBindings;

            container.Bind<GlobalCompositionRoot>().ToInstance(root);
            container.Bind<CompositionRoot>().ToInstance(root);

            container.Install<StandardInstaller>();

            container.Install(GetGlobalInstallers());

            return container;
        }
开发者ID:4xisblack,项目名称:Zenject,代码行数:17,代码来源:GlobalCompositionRoot.cs

示例6: TestValidateDynamicSuccess

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

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

            Assert.That(container.ValidateObjectGraph<Foo>(typeof(Bar)).IsEmpty());
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:8,代码来源:TestValidateInstaller.cs

示例7: TestValidateDynamicFailure2

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

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

            Assert.That(!container.ValidateObjectGraph<Foo>(typeof(Bar), typeof(string)).IsEmpty());
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:8,代码来源:TestValidateInstaller.cs

示例8: BindPriority

        public static void BindPriority(
            DiContainer container, Type tickableType, int priorityCount)
        {
            Assert.That(tickableType.DerivesFrom<IFixedTickable>(),
                "Expected type '{0}' to derive from IFixedTickable", tickableType.Name());

            container.Bind<ModestTree.Util.Tuple<Type, int>>("Fixed").ToInstance(
                ModestTree.Util.Tuple.New(tickableType, priorityCount)).WhenInjectedInto<TickableManager>();
        }
开发者ID:Aszan,项目名称:Zenject,代码行数:9,代码来源:FixedTickablePrioritiesInstaller.cs

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

示例10: OnEnable

        public virtual void OnEnable()
        {
            _container = new DiContainer(StaticContext.Container);

            // Make sure we don't create any game objects since editor windows don't have a scene
            _container.AssertOnNewGameObjects = true;

            _container.Bind<TickableManager>().AsSingle();
            _container.Bind<InitializableManager>().AsSingle();
            _container.Bind<DisposableManager>().AsSingle();
            _container.Bind<GuiRenderableManager>().AsSingle();

            InstallBindings();

            _container.Inject(this);

            _initializableManager.Initialize();
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:18,代码来源:ZenjectEditorWindow.cs

示例11: TestBindAllInterfaces2

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

            container.Bind(x => x.AllInterfaces())
                .To(x => x.AllNonAbstractClasses().InNamespace("Zenject.Tests.Convention.Two"));

            Assert.IsEqual(container.ResolveAll<IFoo>().Count, 2);
            Assert.IsEqual(container.ResolveAll<IBar>().Count, 2);
        }
开发者ID:Soren025,项目名称:Zenject,代码行数:10,代码来源:TestConvention2.cs

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

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

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

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


注:本文中的Zenject.DiContainer.Bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。