【发布时间】:2010-06-23 07:51:51
【问题描述】:
我正在尝试使用 MEF 导出以下内容:
[Export(typeof(IRepository<>))]
public class Repository<T> : IRepository<T>
where T : class
{
导入
[Import(typeof(IRepository<>))]
private IRepository<Contact> repository;
但在编写以下 MEF 时,我不断收到错误消息:
===========================================
构图保持不变。由于以下错误,更改被拒绝: 合成产生了单个合成错误。下面提供了根本原因。查看 CompositionException.Errors 属性以获取更多详细信息。
1) 找不到与约束匹配的有效导出 '((exportDefinition.ContractName = "Interfaces.IRepository()") && (exportDefinition.Metadata.ContainsKey("ExportTypeIdentity") && "Interfaces.IRepository()"。 Equals(exportDefinition.Metadata.get_Item("ExportTypeIdentity"))))',无效的导出可能已被拒绝。
导致:无法在部件 'SoCLINQ2SQL.RepositoryTest' 上设置导入 'SoCLINQ2SQL.RepositoryTest.repository (ContractName="Interfaces.IRepository()")'。 元素:SoCLINQ2SQL.RepositoryTest.repository (ContractName="Interfaces.IRepository()") --> SoCLINQ2SQL.RepositoryTest
【问题讨论】: