Implementing Plugin Architecture - Dynamic DLL loading

强颜欢笑 提交于 2019-11-28 10:37:20

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...

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:

  • 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
mathieu

You should have a look at System.Addin namespace, as it really fits your need. After an addin is developped, you just have to drop it in a folder, and it is available (at runtime) for your application.

See this question for comparison : Choosing between MEF and MAF (System.AddIn)

The MEF or System.Addins routes mentioned are likely the most efficient way to go about this. I only pipe in to say a few things about the alternatives.

I have "hand rolled" this sort of solution a number of times and I would say that unless there is a compelling reason to do it from scratch it is better to use an existing addin framework. But if you are going to do so, I have found dependency injection containers like Castle or (insert your preferred DI container here) to be help handle some of the mechanics.

Also depending on exactly the sort of thing you are looking to do, the approach of embedding a macro language is potentially useful. Iron Python is easily embeddable. And Ayende wrote a very interesting book DSLs in Boo on doing this sort of thing and much more.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!