开发者

What are the steps to get plugin or extension functionality in a C# application?

I've done plugin architectures in Win32 & C/C++ for years, with extension points dynamically loaded from DLLs with LoadLibrary, GetProcAddress, etc.

Now the开发者_高级运维 time has come to C#. What are the corresponding steps there - dynamically load an assembly? Or is it a completely different schema?


Generally, you can look around where you expect plugins, load the assemblies and look for certain classes. Usually plugins advertise themselves by extending some sort of plugin base class or implementing an interface.

Another option would be MEF which will also be part of .NET 4 but the preview releases work on the current .NET framework, too.


You can use classes from System.Addin namespace. See this discussion: Choosing between MEF and MAF (System.AddIn)

Here is a demo too: AddIn Enabled Applications

Another solution is to use Mono.AddIn which seems quite powerful.


In .Net applications we can use AppDomain and AppDomain.CurrentAppDomain to load assemblies dynamically to our application .The problem is that you can unload an assembly once it has been loaded to a AppDomain.There's a workaround to solve this problem that you can load these kind of assemblies in a different AppDomain and unload it whenever you don't want those assemblies.but this approach is very compicated because passing objects between two assemblies in two different AppDomain it's not that easy.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜