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