本文整理汇总了C#中ContainerConfiguration.WithExport方法的典型用法代码示例。如果您正苦于以下问题:C# ContainerConfiguration.WithExport方法的具体用法?C# ContainerConfiguration.WithExport怎么用?C# ContainerConfiguration.WithExport使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ContainerConfiguration
的用法示例。
在下文中一共展示了ContainerConfiguration.WithExport方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ShouldThrowActivationExceptionWhenMoreThanOneInstanceAvailble
public void ShouldThrowActivationExceptionWhenMoreThanOneInstanceAvailble()
{
object myInstance = new object();
object myInstance2 = new object();
ContainerConfiguration config = new ContainerConfiguration();
config.WithExport<object>(myInstance);
config.WithExport<object>(myInstance2);
MefServiceLocatorAdapter.CompositionContainer = config.CreateContainer();
IServiceLocator containerAdapter = new MefServiceLocatorAdapter();
Assert.ThrowsException<ActivationException>(() => containerAdapter.GetInstance(typeof(object)), "Sequence contains more than one element");
}
示例2: ShouldForwardResolveAllToInnerContainer
public void ShouldForwardResolveAllToInnerContainer()
{
object objectOne = new object();
object objectTwo = new object();
ContainerConfiguration config = new ContainerConfiguration();
config.WithExport<object>(objectOne);
config.WithExport<object>(objectTwo);
MefServiceLocatorAdapter.CompositionContainer = config.CreateContainer();
IServiceLocator containerAdapter = new MefServiceLocatorAdapter();
IList<object> returnedList = containerAdapter.GetAllInstances(typeof(object)).ToList();
Assert.AreSame(returnedList[0], objectOne);
Assert.AreSame(returnedList[1], objectTwo);
}
示例3: ShouldForwardResolveToInnerContainerWhenKeyIsUsed
public void ShouldForwardResolveToInnerContainerWhenKeyIsUsed()
{
object myInstance = new object();
ContainerConfiguration config = new ContainerConfiguration();
config.WithExport<object>(myInstance, "key");
MefServiceLocatorAdapter.CompositionContainer = config.CreateContainer();
IServiceLocator containerAdapter = new MefServiceLocatorAdapter();
Assert.AreSame(myInstance, containerAdapter.GetInstance(typeof(object), "key"));
}