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


C# DefaultPicoContainer.GetComponentInstanceOfType方法代码示例

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


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

示例1: ParentComponentRegisteredAsClassShouldBePreffered

		public void ParentComponentRegisteredAsClassShouldBePreffered()
		{
			DefaultPicoContainer parent = new DefaultPicoContainer();
			DefaultPicoContainer child = new DefaultPicoContainer(parent);

			parent.RegisterComponentImplementation(typeof (ITouchable), typeof (AlternativeTouchable));
			child.RegisterComponentImplementation("key", typeof (SimpleTouchable));
			child.RegisterComponentImplementation(typeof (DependsOnTouchable));

			DependsOnTouchable dot = (DependsOnTouchable) child.GetComponentInstanceOfType(typeof (DependsOnTouchable));
			Assert.AreEqual(typeof (AlternativeTouchable), dot.getTouchable().GetType());
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:12,代码来源:ChildContainerTestCase.cs

示例2: ComponensRegisteredWithClassKeyTakePrecedenceOverOthersWhenThereAreMultipleImplementations

		public void ComponensRegisteredWithClassKeyTakePrecedenceOverOthersWhenThereAreMultipleImplementations()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			pico.RegisterComponentImplementation("default", typeof (SimpleTouchable));

			/*
			 * By using a class as key, this should take precedence over the other Touchable (Simple)
			 */
			pico.RegisterComponentImplementation(typeof (ITouchable),
			                                     typeof (DecoratedTouchable),
			                                     new IParameter[] {new ComponentParameter("default")});

			ITouchable touchable = (ITouchable) pico.GetComponentInstanceOfType(typeof (ITouchable));
			Assert.AreEqual(typeof (DecoratedTouchable), touchable.GetType());
		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:15,代码来源:ComponentKeysTestCase.cs

示例3: testIComponentAdapterResolutionIsFirstLookedForByClassKeyToTheTopOfTheContainerHierarchy

		public void testIComponentAdapterResolutionIsFirstLookedForByClassKeyToTheTopOfTheContainerHierarchy()
		{
			DefaultPicoContainer pico = new DefaultPicoContainer();
			pico.RegisterComponentImplementation("default", typeof (SimpleTouchable));

			pico.RegisterComponentImplementation(typeof (ITouchable), typeof (DecoratedTouchable), new IParameter[]
				{
					new ComponentParameter("default")
				});

			DefaultPicoContainer grandChild = new DefaultPicoContainer(new DefaultPicoContainer(new DefaultPicoContainer(pico)));

			ITouchable touchable = (ITouchable) grandChild.GetComponentInstanceOfType(typeof (ITouchable));
			Assert.AreEqual(typeof (DecoratedTouchable), touchable.GetType());

		}
开发者ID:smmckay,项目名称:picocontainer,代码行数:16,代码来源:ComponentKeysTestCase.cs

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