在应用程序中实现插件的设计模式? [英] Design Pattern for implementing plugins in your application?
问题描述
在我的上一个应用程序中,我为所有必须实现的插件创建了一个简单的界面。然后我将所有程序集加载到apps目录中,并抛出任何不实现该接口的程序。
界面中的一种方法是一种DoWork()方法,定期在所有加载的程序集上调用,以执行插件可能具有的任何操作。
执行插件系统的正确方式是什么?你只是为插件创建一个接口?您应该定期在所有插件中调用特定方法吗?有更复杂的方法吗?
编辑:
感谢Matt Hamilton参考System.Addin命名空间。这很可能是我实现我的插件的方式。然而,我仍然对插件架构总体感到好奇,并不介意一些背景,他们应该设计的最好的方式,暗示..你应该如何调用他们一旦加载等。
在dnrTV网站上有一些很棒的演练:
<一个href =http://www.dnrtv.com/default.aspx?showNum=44 =noreferrer> Mark Miller on Demand on Demand
What is the standard way for allowing and implementing a plugin system for your application?
In my last application I made a simple interface for all plugins that they must implement. I then load all assemblies in the apps directory and toss out any that don't implement that interface.
One of the methods in the interface is a DoWork() method that periodically gets called on all loaded assemblies to perform any actions the plugins may have.
What is the "proper" way to do a plugin system? Do you just create an Interface for plugins? Should you periodically call a particular method in all plugins? Is there a more sophisticated way?
EDIT:
Thank you Matt Hamilton for the reference to the System.Addin namespace. This will most likely be the way I implement my plugins. However, I am still curious about plugin architecture in general and wouldn't mind some background on the best way they should be designed, implmemented.. how you should call on them once loaded, etc.
There are some great walkthroughs over on the dnrTV website:
Carl Franklin on Plug-Ins in .NET
Miguel Castro on Extensibility
这篇关于在应用程序中实现插件的设计模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!