當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。