Click to See Complete Forum and Search --> : Plugins in .NET?


Yves M
February 2nd, 2005, 05:58 AM
Hi,

I'm new to .NET (coming from C++) and I would like to design a pluggable architecture for the application. Basically, it should work something along the lines of:
- Main executable
- plugin dlls that can be installed/uninstalled separately

The requirement for the plugins would be that they implement certain interfaces (easy), but they could also have a UI part that would then be integrated into the main UI. This should work a bit like OLE Property pages in C++/COM, but it would be great if it could be done wholly in .NET and not requiring any interop with COM. The basic reasoning is that it should be able to run on Mono as well.

Are there any examples of this kind of architecture in C#, or how would I go about designing this and actually implementing it?

Thanks in advance,

Yves

darwen
February 2nd, 2005, 06:10 AM
Have a look at the reflection namespace with details about how to create classes from dynamcially loaded assemblies.

Assembly.LoadFile loads an assembly into memory from a file, and then you can just reflect on the types in that assembly and create instances of whichever ones you like.

I'd have a look at custom attributes as well because they really come into their own when doing this sort of thing.

If you look at my article about the MDI template in .NET you'll see I attach a 'Document' attribute to the document types so reflection can pick them out of the assembly.

Also the UI stuff you're talking about is considerably easier in .NET than in C++ : you can just create a control using it's constructor (again using reflection) and then just attach it to whichever form you want to. No nasty mucking about with the ActiveX mechanisms and callback methods here ! Just straight in and use.

Darwen.

Andreas Masur
February 2nd, 2005, 06:11 AM
Plug-in Manager (http://www.codeproject.com/csharp/DynamicPluginManager.asp)
Plugin Architecture using C# (http://www.codeproject.com/csharp/C__Plugin_Architecture.asp)
PluginManager (http://www.codeproject.com/csharp/pluginmanager.asp)
Add run-time functionality to your application by providing a plug-in mechanism (http://www.codeproject.com/csharp/plugins.asp)

Yves M
February 2nd, 2005, 06:13 AM
Great, thanks to both of you. I'm in for a bit of reading ;)