public static Dictionary<string, string> Load(string path)
{
if (!System.IO.Directory.Exists(path))
{
throw new System.IO.DirectoryNotFoundException();
}
Dictionary<string, string> pluins = new Dictionary<string,string>();
var files = System.IO.Directory.GetFiles(path);
foreach (var file in files)
{
if (file.ToLower().EndsWith("***") || file.ToLower().EndsWith(".dll"))
{
var assembly = Assembly.LoadFrom(file);
var types = assembly.GetTypes();
foreach (var type in types)
{
if (type.GetInterfaces().Count(c =>c == typeof(IPlugin)) > 0)
{
IPlugin instance = assembly.CreateInstance(type.FullName) as IPlugin;
if (instance != null)
{
_container.RegisterType(typeof(IPlugin), type, type.FullName, new ExternallyControlledLifetimeManager());
var name = string.IsNullOrEmpty(instance.PluginName) ?
type.FullName : instance.PluginName;
name = pluins.ContainsKey(name)?name+"_1":name;
pluins.Add(name, type.FullName);
}
}
}
}
}
return pluins;
}
static IUnityContainer _container = new UnityContainer();