本文整理汇总了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());
}
示例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());
}
示例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());
}
示例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) {}
}