【发布时间】:2011-09-22 15:31:51
【问题描述】:
我有一个非常简单的问题。
可以将插件 DLL 存储在 /Plugin 文件夹而不是 /Bin 中吗?我正在 ASP.NET WebForms(和 MVC)的上下文中尝试插件设计,我想知道将插件 DLL 存储在 /Plugin 文件夹而不是 /Bin 文件夹中是否存在问题。
感谢您的帮助。
更新
我从这篇文章的角度来看这个:http://www.c-sharpcorner.com/UploadFile/40e97e/7192/。
我将使用反射加载插件。
示例代码:
public class PluginLoader
{
public static IList<IPlugin> Load(string folder)
{
IList<IPlugin> plugins = new List<IPlugin>();
// Get files in folder
string[] files = Directory.GetFiles(folder, "*.plug.dll");
foreach(string file in files)
{
Assembly assembly = Assembly.LoadFile(file);
var types = assembly.GetExportedTypes();
foreach (Type type in types)
{
if (type.GetInterfaces().Contains(typeof(IPlugin)))
{
object instance = Activator.CreateInstance(type);
plugins.Add(instance as IPlugin);
}
}
}
return plugins;
}
}
【问题讨论】:
-
取决于您希望如何在运行时加载它们。您看过 MEF - 托管可扩展性框架吗?
-
我打算使用反射。前段时间我看过 MEF,但它似乎有点矫枉过正。不过,随着我获得经验,我可能会看到其中的价值 :-)
标签: c# asp.net asp.net-mvc plugins