1
我已經創建了一個MEF插件控件,可以導入到我的應用程序中。現在,我希望插件能夠從應用中導入零件。我無法確定如何在插件中設置目錄,以便它可以從應用程序中找到導出。有人可以告訴我這是怎麼完成的?下面是我的代碼,當我嘗試用當前正在執行的程序集創建AssemblyCatalog時,它不起作用。MEF:如何從導出的對象導入?
[Export(typeof(IPluginControl))]
public partial class MyPluginControl : UserControl, IPluginControl
[Import]
public string Message { get; set; }
public MyPluginControl()
{
InitializeComponent();
Initialize();
}
private void Initialize()
{
AggregateCatalog catalog = new AggregateCatalog();
catalog.Catalogs.Add(new AssemblyCatalog(Assembly.GetExecutingAssembly()));
CompositionContainer container = new CompositionContainer(catalog);
try
{
container.ComposeParts(this);
}
catch (CompositionException ex)
{
Console.WriteLine(ex.ToString());
}
}
}
謝謝,你說的一切都有幫助,它現在可行! – 2010-08-06 16:51:57