我正在用C#编写一个Addin框架,我想知道如何在不需要重新启动应用程序的情况下使Addin无法加载.
我听说过AppDomains但这些有用吗? Addin可以添加可扩展性类,并且可以通过接口在主AppDomain中调用,并且仍然可以卸载并调用清理代码,导致这些类被删除而该程序集不在主AppDomain中吗?
或者是否有其他方法可以实现无法加载的插件,但是除了AppDomain之外的IIRC,你无法卸载组件.
如果可能的话,我还希望插件引擎与Mono兼容,所以如果可以的话,任何答案都会尝试与Mono保持兼容.
解决方法
你可能想看看
Mono.Addins.有一些好看的样品
here,这里有一些细节:
The following code is a basic example of an add-in host application.
This application runs a set of commands which can be implemented by
add-ins:
using System; using Mono.Addins; [assembly:AddinRoot ("HelloWorld","1.0")] class MainClass { public static void Main () { AddinManager.Initialize (); AddinManager.Registry.Update (); foreach (ICommand cmd in AddinManager.GetExtensionObjects<ICommand> ()) cmd.Run (); } }
The extension point for the above example can be declared like this:
using Mono.Addins; [TypeExtensionPoint] public interface ICommand { void Run (); }
An add-in extending the above extension point would look like this:
using System; using Mono.Addins; [assembly:Addin] [assembly:AddinDependency ("HelloWorld","1.0")] [Extension] public class HelloCommand: ICommand { public void Run () { Console.WriteLine ("Hello World!"); } }