1

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?

Johann Gerell
  • 24,991
  • 10
  • 72
  • 122
  • 1
    http://stackoverflow.com/questions/tagged/ioc+c%23 and http://stackoverflow.com/questions/tagged/plugins+c%23 – jmservera Jan 28 '10 at 09:52
  • @jmservera:those links are not valid. – Kevin Brock Jan 28 '10 at 09:54
  • @Kevin Brock, if you mean they are broken check those ones: http://stackoverflow.com/questions/tagged?tagnames=ioc%2bc%23&sort=votes http://stackoverflow.com/questions/tagged?tagnames=plugins%2bc%23&sort=votes – jmservera Jan 28 '10 at 10:37
  • @jmservera: Sorry, I'm used to seeing links to specific questions. This was my first time seeing links to groups of questions based on tags. – Kevin Brock Jan 28 '10 at 11:28

3 Answers3

3

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.

Joey
  • 344,408
  • 85
  • 689
  • 683
  • MEF has been around for a while, and runs on 3.5, if not 3.0. – Jay Jan 28 '10 at 09:53
  • @Jay: Did I say anything about it *not* running currently? Clarifying, though. However, I'm not entirely sure how good an idea it is to use the preview releases in applications. I've done that once and by now the API did change quite a bit. – Joey Jan 28 '10 at 09:54
1

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.

Community
  • 1
  • 1
Giorgi
  • 30,270
  • 13
  • 89
  • 125
1

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.

Beatles1692
  • 5,214
  • 34
  • 65