469,623 Members | 2,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,623 developers. It's quick & easy.

Plugin System with C#

Dear NG,

I want to create a Plugin System in C# (WinForms). Has anybody experience
about this, tips, tricks, or any links. Thank you very much

The DotNetJunkie
Nov 15 '05 #1
2 20674
Hi Rudolf,
I want to create a Plugin System in C# (WinForms). Has anybody experience
about this, tips, tricks, or any links. Thank you very much


Have a look here:
http://www.codeproject.com/csharp/livecodedotnet.asp

Regards,

--
Frank Eller [.NET MVP]
www.frankeller.de
..NET Developers Group Munich- www.munichdot.net
Nov 15 '05 #2
Hello,

You will need to use Reflection
You should also consider using interfaces

Assemblies:
1) MyApp.exe - the entrypoint and main program
2) PluginHelper.dll - Defines the plugin interface(s). Provides routines to
dynamically load an assembly and return an object that implements a plugin
interface.
3) MyPlugin1.dll, MyPlugin2.dll, etc - implements the plugin interface

All assemblies reference PluginHelper.dll so keep this assembly small and
keep changes to a minimum.

<code assembly="MyApp.exe">
// use static loader when you need to get multiple instances from the same
assembly
PluginHelper helper=PluginHelper.LoadPlugin("MyPlugin1.dll");
IPlugin plugin=(IPlugin) helper.CreateInstance("IPlugin");
plugin.DoSomething();

...or...

// use static instantiator when you only need one instance from an assembly
IPlugin plugin=(IPlugin)
PluginHelper.CreateInstance("MyPlugin1.dll","IPlug in");
plugin.DoSomething();
</code>

Every interface you need will have to be in PluginHelper.dll.
Define these first!
How you implement PluginHelper is up to you.

You might want it to search the current subdirectory instead of supplying an
assembly name.
You may want to try and use attributes to mark assemblies as plugin
assemblies to save you some time searching.
You may want to try and use attributes to mark classes as plugin classes for
the same reason
You might want to look at caching the assemblies/classes for faster future
searches.
You might want to put a factory class inside each assembly and use the
factory to instantiate the objects inside it instead.
This is great when an assembly implements many classes and it avoids
ambiguity as to which class to return when searching for an "entrypoint"
instance to return in an assembly. This way, an assembly can implement many
plugin interfaces but still be treated as one object.

<code>
// static loader looks for and returns an IPluginFactory object
IPluginFactory factory=PluginHelper.Load("MyPlugin2.dll")
factory.CreateClass1();
factory.CreateClass2();
factory.Find("car");
</code>

This can get as complex as you like but the basics are there

Good luck...
Oscar Papel
"Rudolf" <rb***@edu.uni-klu.ac.at> wrote in message
news:OK**************@TK2MSFTNGP12.phx.gbl...
Dear NG,

I want to create a Plugin System in C# (WinForms). Has anybody experience
about this, tips, tricks, or any links. Thank you very much

The DotNetJunkie

Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Reinhold Birkenfeld | last post: by
2 posts views Thread by Matt | last post: by
reply views Thread by David Levine | last post: by
2 posts views Thread by Edvard Majakari | last post: by
reply views Thread by Zeya | last post: by
8 posts views Thread by Flavio | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.