StructureMap 动态加载插件 Dll's
问题: 将插件加载到控制台应用程序(最终为Windows服务)并在dll的研究中的插件中运行代码
: StructureMap 文档(当然) 一些 stackoverflow 线程,这是最接近的。 使用 StructureMap 创建插件扫描仪
我有 3 个项目: 控制台应用程序(驱动程序) 2 类库
Console App
static void Main(string[] args)
{
ObjectFactory.Initialize(cfg => cfg.Scan(scanner =>
{
scanner.AssembliesFromPath(@"PATH TO PLUGIN DIR");
scanner.AddAllTypesOf<IPlugable>();
}));
var list = ObjectFactory.GetAllInstances<IPlugable>();
foreach (var plug in list)
{
plug.Run();
}
}
public interface IPlugable
{
void Run();
}
Plugin_2
public interface IPlugable
{
void Run();
}
public class PlugIn2 : IPlugable
{
public void Run()
{
Console.WriteLine(this.GetType().Name + "fired!");
}
}
public interface IPlugable
{
void Run();
}
public class PlugIn1 : IPlugable
{
public void Run()
{
Console.WriteLine(this.GetType().Name + "fired!");
}
}
输出:
ObjectFactory.GetAllInstances<IPlugable>();
不返回任何对象:( 期望的输出: Plugin_1 和 Plugin_1 的 2 个对象实例Plugin_2
提前致谢。
Problem:
Loading Plugins into a console app(Windows Service Eventually) and running code in the plug in dll's
Research:
StructureMap Docs(of course)
A few stackoverflow threads this one being the closest.
Creating plugin scanner with StructureMap
I have 3 projects:
Console App (Driver)
2 Class libraries
Console App
static void Main(string[] args)
{
ObjectFactory.Initialize(cfg => cfg.Scan(scanner =>
{
scanner.AssembliesFromPath(@"PATH TO PLUGIN DIR");
scanner.AddAllTypesOf<IPlugable>();
}));
var list = ObjectFactory.GetAllInstances<IPlugable>();
foreach (var plug in list)
{
plug.Run();
}
}
public interface IPlugable
{
void Run();
}
Plugin_2
public interface IPlugable
{
void Run();
}
public class PlugIn2 : IPlugable
{
public void Run()
{
Console.WriteLine(this.GetType().Name + "fired!");
}
}
public interface IPlugable
{
void Run();
}
public class PlugIn1 : IPlugable
{
public void Run()
{
Console.WriteLine(this.GetType().Name + "fired!");
}
}
The Output:
ObjectFactory.GetAllInstances<IPlugable>();
returns no objects :(
Desired Output:
2 Object Instances of Plugin_1 & Plugin_2
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在使用 3 个不同的界面。它们都被称为“IPlugable”,但驻留在不同的命名空间中,因此它们并不相同。
Looks like you are using 3 different interfaces. They are all called "IPlugable", but reside in different namespaces, hence they are not the same.
我想这就是我想要的答案..
托管可扩展性框架
http://msdn.microsoft.com/en-us/library/dd460648.aspx
当你找到一个新的框架来找到问题的确切解决方案时,你一定会喜欢它。
I think this is the answer I am going with..
Managed Extensibility Framework
http://msdn.microsoft.com/en-us/library/dd460648.aspx
Got to love it when you find a new framework to find the exact solution to your problem.