Hey, I'm working on a project in C#, it's about E-learning.This project should use plug-ins as its main inputs, it can't function without them. I have no idea how can I work with plug-ins, I know nothing about how can a plug-in compile inside my program, or how can I install them inside my application. I'm asking here about references, or any useful ideas that can help me with this.
+3
A:
Start by creating a Plug-In Interface:
public interface IPlugIn
{
// Your stuff here
}
You can then distribute your interface to the developers working on the plugins.
When your application starts up, it can load all Plug-In assemblies dynamically, then work with them through the IPlugIn
interface without needing to know the internals of each one.
UPDATE
I actually found an article that goes into the process I described in more depth with more ellaborate examples. You can check it out here:
Writing Plugin-Based Applications in .NET
And an added bonus...it comes with Code Samples!
Justin Niessner
2010-03-05 15:12:49
Thanks so much I think I'll go with this simple method, if you have more experience or references about this please let me know, thanks again :)
Shaza
2010-03-14 23:53:48
+1
A:
if your plugin is not too complex you can avoid using extensibility frameworks like MEF.
- You define contract for plugin. It should be public interface, or may be class with abstract/virtual methods. You should move it to separate assembly and distribute to plugin developers
- Developers implement interface and produce assemblies
- Use Assembly.Load to load in runtime.
- List types by GetTypes
- Find types that implement your interface
- Activator.CreateInstance
- Have fun
Andrey
2010-03-05 15:19:33