【发布时间】:2014-10-30 19:48:46
【问题描述】:
我是 MEF 的新手,我正在尝试使用 MEF 框架为我的 C# 应用程序添加插件可扩展性。
我正在从数据库下载插件并通过 byte[] 数据加载。
this.PluginCatalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load(RawData)));
在尝试使用插件基类之前,一切都像魔术一样工作。
我的一个插件看起来像:
using System;
using System.Net;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Reflection;
using PluginCommon;
namespace Plugins
{
[Export("Plugin", typeof(IPlugin))]
[PluginMetadata("DownloadManager", "1.0")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class DownloadManager : INGPlugin
{
WebClient Client = new WebClient();
public string _text = "qwert";
public AsyncCompletedEventHandler dc { get; set; }
public DownloadProgressChangedEventHandler pc { get; set; }
public void Download(string url, string path)
{
Client.DownloadProgressChanged += this.pc;
Client.DownloadFileCompleted += this.dc;
Client.DownloadFileAsync(new Uri(url), path);
}
}
}
要使用这个插件,我需要创建一个类型为 DownloadManager 的变量。我的大多数插件都与此示例相同。我需要创建具有相同类型插件的插件实例。
我认为我使用了错误的方法,有人可以给我一些例子吗?
最好的问候,
【问题讨论】: