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


C# ContainerConfiguration.WithExport方法代码示例

本文整理汇总了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");
        }
开发者ID:xperiandri,项目名称:PortablePrism,代码行数:13,代码来源:MefServiceLocatorAdapterFixture.cs

示例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);
        }
开发者ID:xperiandri,项目名称:PortablePrism,代码行数:16,代码来源:MefServiceLocatorAdapterFixture.cs

示例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"));
        }
开发者ID:xperiandri,项目名称:PortablePrism,代码行数:12,代码来源:MefServiceLocatorAdapterFixture.cs


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