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