在此先感謝您的幫助。我有以下的出口部分:MEF組合.NET 4.0
[Export (typeof(INewComponent))] // orignally tried just [Export} here and importing NewComponent below
public class NewComponent : INewComponent
{
// does stuff including an import
}
控制檯測試程序進口上述:
public class Program
{
[Import] // have tried variations on importing "NewComponent NewComponent" etc
public INewComponent NewComponent
{
get;
set;
}
public static void Main(string[] args)
{
var p = new Program();
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
container.ComposeParts(p);
}
的組成失敗,這些CompositionExceptions(我刪除,以保護犯罪:)命名空間):
1)未找到符合約束的有效導出 '((exportDefinition.ContractName ==「INewComponent」)AndAlso (exportDefinition .Metadata.ContainsKey(「ExportTypeIdentity」)AndAlso 「INewComponent」.Equals(exportDefinition.Metadata.get_Item(「ExportTypeIdentity」))))', 無效導出可能已被拒絕。
的組合工作方式成功,如果我做的組成在這樣的主程序:
public class Program
{
public static void Main(string[] args)
{
INewComponent newComponent = new NewComponent();
var catalog = new AssemblyCatalog(typeof(Program).Assembly);
var container = new CompositionContainer(catalog);
container.ComposeParts(newComponent);
}
}
謝謝
謝謝吉姆。是的,NewComponent是在一個DLL中,上面的技巧。我需要回去重新閱讀Block關於MEF的原始MSDN文章:)。在H2上的博客thx開始與Visual MEFX。完善。 –