实现插件架构-动态DLL加载 [英] Implementing Plugin Architecture - Dynamic DLL loading

查看:116
本文介绍了实现插件架构-动态DLL加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基本上是带有预加载控件的设计器的应用程序,您可以在其中使用控件来设计页面。

I've an application which is basically a designer with preloaded controls where you can design your pages using the controls.

我计划发布越来越多的控件控制未来。我不想为新添加的控件发布新版本,因为它有缺点。因此,我想到的是插件/插件类型的体系结构,我只是单独发布插件/插件,它们可以安装并在设计器中获取控件。

I'm planning to release more and more controls in the future. I don't want to release a new build for newly added controls as it has its disadvantages. So I was thinking of addon/plugin kind of architecture where I just release the addon/plugin separately which they can install and get the controls inside the designer.

现在,我我使用xml文件作为插件来指定控件,其行为,其样式等。每个xml(插件)都代表一个控件。但是我发现很难实现这一点,因为我必须编写一个通用解析器来读取所有插件。

Right now I'm using xml files as addons to specify the controls, its behaviors, its styles etc. Each xml (addon) represents a single control. But I'm finding it very difficult to implement this since I've to write a generic parser to read all the plugins.

相反,我可以为每个释放一个dll吗? addon,它使我有更多控制权来编写代码以定义控件的行为/外观并通过主机动态加载它?如果是这样,我如何检查dll并将其动态加载到我的应用程序中?

Instead, can I release a dll for each addon which gives me more control to write code to define the behavior/look of the control and dynamically load it through the main engine? If so how can I check for dlls and load it dynamically in my application?

推荐答案

您可能想看看托管扩展框架。这可能会解决您的大多数问题,甚至更多,但是将需要学习一些新技术...

You might want to look at the Managed Extensibility Framework. This will probably solve most of your issues and more, but will require learning some new tech...

您还应该肯定使用系统.addin 像Mathieu所建议的那样命名空间!

You should also definitely look into the System.Addin Namespace as mathieu suggests!

如果您想使用自己的路线,建议使用以下方法:

If you want to go with your own route, I suggest the following approach:


  • 主应用程序中插件的接口

  • 在插件dll中实现该接口

  • 使用 Assembly.Load


    • 在运行时加载dll。将插件组合成单独的AppDomain

    • an interface for addons in your main application
    • implement that interface in addon dlls
    • load the dlls at runtime with Assembly.Load
      • you might want to look into loading the addon assemblies into a separate AppDomain

      这篇关于实现插件架构-动态DLL加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆