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


C# DefaultPicoContainer.GetComponentInstance方法代码示例

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


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

示例1: DefaultPicoContainerReturnsNewInstanceForEachCallWhenUsingTransientIComponentAdapter

		public void DefaultPicoContainerReturnsNewInstanceForEachCallWhenUsingTransientIComponentAdapter()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			picoContainer.RegisterComponentImplementation(typeof (Service));
			picoContainer.RegisterComponent(new ConstructorInjectionComponentAdapter(typeof (TransientComponent), typeof (TransientComponent)));
			TransientComponent c1 = (TransientComponent) picoContainer.GetComponentInstance(typeof (TransientComponent));
			TransientComponent c2 = (TransientComponent) picoContainer.GetComponentInstance(typeof (TransientComponent));
			Assert.IsFalse(c1.Equals(c2));
			Assert.AreSame(c1.service, c2.service);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:10,代码来源:TransientComponentAdapterTestCase.cs

示例2: WrapComponentInstances

        protected virtual IPicoContainer WrapComponentInstances(Type decoratingComponentAdapterClass,
                                                                IPicoContainer picoContainer,
                                                                object[] wrapperDependencies)
        {
            Assert.IsTrue(typeof (DecoratingComponentAdapter).IsAssignableFrom(decoratingComponentAdapterClass));
            IMutablePicoContainer mutablePicoContainer = new DefaultPicoContainer();
            int size = (wrapperDependencies != null ? wrapperDependencies.Length : 0) + 1;
            ICollection allComponentAdapters = picoContainer.ComponentAdapters;

            foreach (object adapter in allComponentAdapters)
            {
                IParameter[] parameters = new IParameter[size];
                parameters[0] = new ConstantParameter(adapter);
                for (int i = 1; i < parameters.Length; i++)
                {
                    parameters[i] = new ConstantParameter(wrapperDependencies[i - 1]);
                }
                IMutablePicoContainer instantiatingPicoContainer =
                    new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory());
                instantiatingPicoContainer.RegisterComponentImplementation("decorator", decoratingComponentAdapterClass,
                                                                           parameters);
                mutablePicoContainer.RegisterComponent(
                    (IComponentAdapter) instantiatingPicoContainer.GetComponentInstance("decorator"));
            }
            return mutablePicoContainer;
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:26,代码来源:AbstractComponentAdapterTestCase.cs

示例3: ComponentParameterExcludesSelf

		public void ComponentParameterExcludesSelf()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			IComponentAdapter adapter = pico.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

			Assert.IsNotNull(pico.GetComponentInstance(typeof (ITouchable)));
			ITouchable touchable = (ITouchable) ComponentParameter.DEFAULT.ResolveInstance(pico, adapter, typeof (ITouchable));
			Assert.IsNull(touchable);
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:9,代码来源:ParameterTestCase.cs

示例4: ComponentParameterFetches

        public void ComponentParameterFetches()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();
            pico.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));
            ComponentParameter parameter = new ComponentParameter(typeof (ITouchable));

            Assert.IsNotNull(pico.GetComponentInstance(typeof (ITouchable)));
            ITouchable touchable = (ITouchable) parameter.ResolveInstance(pico, null, typeof (ITouchable));
            Assert.IsNotNull(touchable);
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:10,代码来源:ParameterTestCase.cs

示例5: ResolveFromParentByType

		public void ResolveFromParentByType()
		{
			IMutablePicoContainer parent = new DefaultPicoContainer();
			parent.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

			IMutablePicoContainer child = new DefaultPicoContainer(parent);
			child.RegisterComponentImplementation(typeof (DependsOnTouchable));

			Assert.IsNotNull(child.GetComponentInstance(typeof (DependsOnTouchable)));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:10,代码来源:ChildContainerTestCase.cs

示例6: ResolveFromGrandParentByKey

        public void ResolveFromGrandParentByKey()
        {
            IMutablePicoContainer grandParent = new DefaultPicoContainer();
            grandParent.RegisterComponentImplementation(typeof (ITouchable), typeof (SimpleTouchable));

            IMutablePicoContainer parent = new DefaultPicoContainer(grandParent);

            IMutablePicoContainer child = new DefaultPicoContainer(parent);
            child.RegisterComponentImplementation(typeof (DependsOnTouchable), typeof (DependsOnTouchable),
                                                  new IParameter[] {new ComponentParameter(typeof (ITouchable))});

            Assert.IsNotNull(child.GetComponentInstance(typeof (DependsOnTouchable)));
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:13,代码来源:ChildContainerTestCase.cs

示例7: NormalExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption

		public void NormalExceptionThrownInCtorIsRethrownInsideInvocationTargetExeption()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			picoContainer.RegisterComponentImplementation(typeof (NormalExceptionThrowing));
			try
			{
				picoContainer.GetComponentInstance(typeof (NormalExceptionThrowing));
				Assert.Fail();
			}
			catch (PicoInvocationTargetInitializationException e)
			{
				Assert.AreEqual("test", e.GetBaseException().Message);
			}
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:14,代码来源:ConstructorInjectionComponentAdapterTestCase.cs

示例8: StartStopStartStopAndDispose

 public void StartStopStartStopAndDispose()
 {
     DefaultPicoContainer pico = new DefaultPicoContainer();
     pico.RegisterComponentImplementation(typeof (One));
     pico.RegisterComponentImplementation(typeof (Two));
     pico.RegisterComponentImplementation(typeof (Three));
     pico.RegisterComponentImplementation(typeof (Four));
     One one = (One) pico.GetComponentInstance(typeof (One));
     object o = pico.ComponentInstances;
     // instantiation - would be difficult to do these in the wrong order!!
     Assert.AreEqual(4, one.getInstantiating().Count);
     Assert.AreEqual("One", one.getInstantiating()[0]);
     Assert.AreEqual("Two", one.getInstantiating()[1]);
     Assert.AreEqual("Three", one.getInstantiating()[2]);
     Assert.AreEqual("Four", one.getInstantiating()[3]);
     StartStopDisposeLifecycleComps(pico, pico, pico, one);
 }
开发者ID:smmckay,项目名称:picocontainer,代码行数:17,代码来源:DefaultPicoContainerLifecycleTestCase.cs

示例9: StartStopOfDaemonizedThread

        public void StartStopOfDaemonizedThread()
        {
            DefaultPicoContainer pico = new DefaultPicoContainer();
            pico.RegisterComponentImplementation(typeof (FooRunnable));

            object i = pico.ComponentInstances;
            pico.Start();
            Thread.Sleep(100);
            pico.Stop();

            FooRunnable foo = (FooRunnable) pico.GetComponentInstance(typeof (FooRunnable));
            Assert.AreEqual(1, foo.runCount());
            pico.Start();
            Thread.Sleep(100);
            pico.Stop();
            Assert.AreEqual(2, foo.runCount());
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:17,代码来源:DefaultPicoContainerLifecycleTestCase.cs

示例10: OnlyStartableComponentsAreInstantiatedOnStart

        public void OnlyStartableComponentsAreInstantiatedOnStart()
        {
            IMutablePicoContainer pico = new DefaultPicoContainer();
            pico.RegisterComponentImplementation("recording", typeof (StringBuilder));
            pico.RegisterComponentImplementation(typeof (A));
            pico.RegisterComponentImplementation(typeof (NotStartable));
            pico.Start();

            pico.Stop();
            pico.Dispose();
            Assert.AreEqual("<AA>!A", pico.GetComponentInstance("recording").ToString());
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:12,代码来源:DefaultPicoContainerLifecycleTestCase.cs

示例11: ComponentsAreStartedBreadthFirstAndStoppedDepthFirst

        public void ComponentsAreStartedBreadthFirstAndStoppedDepthFirst()
        {
            IMutablePicoContainer parent = new DefaultPicoContainer();
            parent.RegisterComponentImplementation("recording", typeof (StringBuilder));
            parent.RegisterComponentImplementation(typeof (A));
            IMutablePicoContainer child = parent.MakeChildContainer();
            child.RegisterComponentImplementation(typeof (B));
            parent.Start();
            parent.Stop();

            Assert.AreEqual("<A<BB>A>", parent.GetComponentInstance("recording").ToString());
        }
开发者ID:smmckay,项目名称:picocontainer,代码行数:12,代码来源:DefaultPicoContainerLifecycleTestCase.cs

示例12: ShouldNotConsiderNonPublicConstructors

		public void ShouldNotConsiderNonPublicConstructors()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			pico.RegisterComponentImplementation(typeof (Component201));
			pico.RegisterComponentInstance(2);
			pico.RegisterComponentInstance(true);
			pico.RegisterComponentInstance("Hello");
			Assert.IsNotNull(pico.GetComponentInstance(typeof (Component201)));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:9,代码来源:ConstructorInjectionComponentAdapterTestCase.cs

示例13: ShouldBeAbleToInstantiateNonPublicClassesWithNonPublicConstructors

		public void ShouldBeAbleToInstantiateNonPublicClassesWithNonPublicConstructors()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer(new ConstructorInjectionComponentAdapterFactory(true));
			pico.RegisterComponentImplementation(typeof (Private));
			pico.RegisterComponentImplementation(typeof (NotYourBusiness));
			Assert.IsNotNull(pico.GetComponentInstance(typeof (NotYourBusiness)));
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:7,代码来源:ConstructorInjectionComponentAdapterTestCase.cs

示例14: PicoInitializationExceptionThrownBecauseOfFilteredConstructors

		public void PicoInitializationExceptionThrownBecauseOfFilteredConstructors()
		{
			DefaultPicoContainer picoContainer = new DefaultPicoContainer();
			try
			{
				picoContainer.RegisterComponentImplementation(typeof (IllegalAccessExceptionThrowing));
				picoContainer.GetComponentInstance(typeof (IllegalAccessExceptionThrowing));
				Assert.Fail();
			}
			catch (PicoInitializationException e)
			{
				Assert.IsTrue(e.Message.IndexOf(typeof (IllegalAccessExceptionThrowing).Name) > 0);
			}
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:14,代码来源:ConstructorInjectionComponentAdapterTestCase.cs

示例15: TestCollections

		public void TestCollections()
		{
			IMutablePicoContainer mpc = new DefaultPicoContainer();
			IParameter[] parameters = new IParameter[]{new ComponentParameter(typeof(Cod), false), 
														  new ComponentParameter(typeof(Fish), false)};

			mpc.RegisterComponentImplementation(typeof(CollectedBowl), typeof(CollectedBowl), parameters);
			mpc.RegisterComponentImplementation(typeof(Cod));
			mpc.RegisterComponentImplementation(typeof(Shark));
			Cod cod = (Cod) mpc.GetComponentInstanceOfType(typeof(Cod));
			CollectedBowl bowl = (CollectedBowl) mpc.GetComponentInstance(typeof(CollectedBowl));
			Assert.AreEqual(1, bowl.cods.Length);
			Assert.AreEqual(2, bowl.fishes.Length);
			Assert.AreSame(cod, bowl.cods[0]);

			try
			{
				Assert.AreSame(bowl.fishes[0], bowl.fishes[1]);
				Assert.Fail("The fishes should not be the same");
			}
			catch(AssertionException) {}
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:22,代码来源:CollectionComponentParameterTestCase.cs


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