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


C# Container.ResolveAll方法代码示例

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


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

示例1: ShouldNotBuildTwice

        public void ShouldNotBuildTwice()
        {
            var container = new Container();
            container.Register<InterfaceA, ClassA1>();
            container.Register<InterfaceA, ClassA2>();

            var all = container.ResolveAll<InterfaceA>().ToArray();
            var all2 = container.ResolveAll<InterfaceA>().ToArray();

            Assert.AreEqual(2, all.Length);
            Assert.AreEqual(2, all2.Length);

            Assert.AreSame(all[0], all2[0]);
            Assert.AreSame(all[1], all2[1]);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:15,代码来源:MultipleRegistrations.cs

示例2: InitialiseContainerWithBootstrapper

        private static IContainer InitialiseContainerWithBootstrapper(IBootstrapper containerBootstrapper)
        {
            IContainer container = new Container();

            try
            {
                if (!ApplicationServiceLocator.IsInitializedSuccessfully)
                {
                    ApplicationServiceLocator.InitializeAsync(container, containerBootstrapper).Wait();
                }
                else
                {
                    container = ApplicationServiceLocator.Container;
                }
            }
            catch (Exception exception)
            {
                Trace.TraceError(exception.Message);
            }

            DependencyResolver.SetResolver(
                x => container.HasComponent(x) ? container.Resolve(x) : null,
                x => container.HasComponent(x) ? container.ResolveAll(x) : new object[0]);

            return container;
        }
开发者ID:endjin,项目名称:Endjin.Composition,代码行数:26,代码来源:MvcContainerConfig.cs

示例3: Should_resolve_all_instances

        public void Should_resolve_all_instances()
        {
            // Arrange
            IContainer container = new Container();

            // Act & assert
            var instancesBefore = container.ResolveAll<ITypeToResolve>();
            Assert.That(instancesBefore.Count(), Is.EqualTo(0));

            container.Register<ITypeToResolve>(ctx => new ConcreteType());
            container.Register<ITypeToResolve>(ctx => new ConcreteType2());
            container.Register<ITypeToResolve>(ctx => new ConcreteType3());

            var instancesAfter = container.ResolveAll<ITypeToResolve>();
            Assert.That(instancesAfter.Count(), Is.EqualTo(3));
        }
开发者ID:cguedes,项目名称:FluentSecurity,代码行数:16,代码来源:ContainerSpec.cs

示例4: ShouldRemoveExecutionContextInstanceOnly

        public void ShouldRemoveExecutionContextInstanceOnly()
        {
            var instance1 = new TestClass();
            var instance2 = new TestClass();

            var container = new Container();
            container.Inject<TestInterface>(instance1, Lifecycle.HttpContextOrExecutionContextLocal);

            TestInterface[] thread2ResolvedTestClasses = null;
            bool thread2HasRegistration = true;
            ExecutionContext.SuppressFlow();
            var thread2 = new Thread(() =>
            {
                container.Inject<TestInterface>(instance2, Lifecycle.HttpContextOrExecutionContextLocal);

                thread2ResolvedTestClasses = container.ResolveAll<TestInterface>().ToArray();

                container.RemoveInstancesOf<TestInterface>(Lifecycle.HttpContextOrExecutionContextLocal);

                thread2HasRegistration = container.HasRegistrationFor<TestInterface>();
            });

            thread2.Start();
            thread2.Join(1000);
            ExecutionContext.RestoreFlow();
            Assert.IsFalse(thread2HasRegistration);
            Assert.AreEqual(1, thread2ResolvedTestClasses.Length);

            Assert.AreEqual(instance1, container.Resolve<TestInterface>());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:30,代码来源:RemovingInstances.cs

示例5: ShouldReturnEmptyEnumerable

        public void ShouldReturnEmptyEnumerable()
        {
            var container = new Container();

            var xs = container.ResolveAll<InterfaceA>();

            Assert.AreEqual(0, xs.Count());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:8,代码来源:MultipleRegistrations.cs

示例6: ShouldRemoveInstances

        public void ShouldRemoveInstances()
        {
            var container = new Container();
            container.Inject<InterfaceA>(new ClassA1());
            container.Register<InterfaceA, ClassA2>();

            container.RemoveAllRegistrationsAndInstancesOf<InterfaceA>();

            Assert.AreEqual(0, container.ResolveAll<InterfaceA>().Count());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:10,代码来源:RemovingRegistrations.cs

示例7: ShouldResolveAll

        public void ShouldResolveAll()
        {
            var container = new Container();
            container.Register<InterfaceA, ClassA1>();
            container.Register<InterfaceA, ClassA2>();

            var all = container.ResolveAll<InterfaceA>().ToArray();

            Assert.AreEqual(2, all.Length);
            Assert.IsInstanceOf<ClassA1>(all[0]);
            Assert.IsInstanceOf<ClassA2>(all[1]);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:12,代码来源:MultipleRegistrations.cs

示例8: ShouldConstruct

        public void ShouldConstruct()
        {
            var container = new Container();

            container.RunAllTypeProcessors();

            var instances = container.ResolveAll<TestInterface>().ToArray();

            Assert.AreEqual(typeof(TestClass1), instances[0].GetType());
            Assert.AreEqual(typeof(TestClass2), instances[1].GetType());
            Assert.AreEqual(typeof(TestClass3), instances[2].GetType());
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:12,代码来源:TypeProcessors.cs

示例9: Should_resolve_instances_from_primary_source

        public void Should_resolve_instances_from_primary_source()
        {
            // Arrange
            var expectedInstances = new List<object> { new ConcreteType3(), new ConcreteType3() };
            IContainer container = new Container();
            container.SetPrimarySource(ctx => new FakeContainerSource(expectedInstances));

            // Act
            var instance = container.ResolveAll(typeof(ConcreteType3));

            // Assert
            Assert.That(instance, Is.EqualTo(expectedInstances));
        }
开发者ID:cguedes,项目名称:FluentSecurity,代码行数:13,代码来源:ContainerSpec.cs

示例10: ShouldResolveSameInstance

        public void ShouldResolveSameInstance()
        {
            var container = new Container();

            container.Register<TestInterface>(c => new TestClass());

            var resolved1 = container.Resolve<TestInterface>();
            var resolved2 = container.Resolve<TestInterface>();

            var resolvedAll = container.ResolveAll<TestInterface>().ToArray();
            Assert.AreEqual(1, resolvedAll.Length);

            Assert.AreSame(resolved1, resolved2);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:14,代码来源:CustomCtors.cs

示例11: ShouldResolveRegisteredAndInjected

        public void ShouldResolveRegisteredAndInjected()
        {
            var container = new Container();

            container.Register<TestInterface, TestClass>();

            var testClass = new TestClass2();
            container.Inject<TestInterface>(testClass);

            var instances = container.ResolveAll<TestInterface>().ToArray();

            Assert.AreEqual(2, instances.Length);

            Assert.AreNotSame(instances[0], instances[1]);
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:15,代码来源:InjectingInstances.cs

示例12: ShouldThrowWhenNoRegistrations

        public void ShouldThrowWhenNoRegistrations()
        {
            var container = new Container();

            try
            {
                container.ResolveAll<InterfaceA>().ToArray();
            }
            catch(ContainerException e)
            {
                Assert.AreEqual("No types registered for `NanoIoC.Tests.MultipleRegistrations+InterfaceA, NanoIoC.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null`", e.Message);
            }
        }
开发者ID:trullock,项目名称:NanoIoC,代码行数:13,代码来源:MultipleRegistrations.cs

示例13: Should_return_empty_list_when_resolving_type_that_is_not_registered

        public void Should_return_empty_list_when_resolving_type_that_is_not_registered()
        {
            // Arrange
            IContainer container = new Container();

            // Act
            var instances = container.ResolveAll(typeof(ConcreteType));

            // Assert
            Assert.That(instances, Is.Not.Null);
            Assert.That(instances, Is.InstanceOf(typeof(IEnumerable<object>)));
        }
开发者ID:cguedes,项目名称:FluentSecurity,代码行数:12,代码来源:ContainerSpec.cs

示例14: CanResolveAll

        public void CanResolveAll()
        {
            // Arrange
            var sut = new Container();
            sut.Register<C, IC>(new C());
            sut.Register<B, IB>();
            sut.Register<A, IA>(c => new A(c.Resolve<IB>(), c.Resolve<IC>()));
            sut.Register<A2, IA>();

            // Assert
            var allA = sut.ResolveAll<IA>();
            Assert.NotEmpty(allA);
            Assert.Equal(2, allA.Count());
        }
开发者ID:skovsboll,项目名称:PicoIoC,代码行数:14,代码来源:PicoIoCTests.cs

示例15: Non_Generic_Named_ResolveAll_Returns_Correct_Services

        public void Non_Generic_Named_ResolveAll_Returns_Correct_Services()
        {
            var target = new Container();

            target.Register<ISimpleTestService>(c => new SimpleTestService());
            target.Register<ISimpleTestService>("Second", c => new SecondSimpleTestService());

            var allResolved = target.ResolveAll(typeof(ISimpleTestService)).ToArray();

            var simpleTestServicesResolved = allResolved.OfType<SimpleTestService>().ToArray();
            var secondSimpleTestServicesResolved = allResolved.OfType<SecondSimpleTestService>().ToArray();

            Assert.AreEqual(2, allResolved.Length);
            Assert.AreEqual(1, simpleTestServicesResolved.Length);
            Assert.AreEqual(1, secondSimpleTestServicesResolved.Length);
        }
开发者ID:andlju,项目名称:Petite,代码行数:16,代码来源:ContainerCoreTests.cs


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