I want to know that how design application , actually applications like Firefox or Chrome that you can download add-on for them and use ??!! How do it in .Net ???
3 Answers
How to allow others to make Add-Ons for your app?
1>You create a DLL
which has an interface
.This interface
defines a set of methods,properties,events you want others to define and implement.
the plugin developer need to define this interface.This DLL is required by your app and the plugin developer..
2>The plugin developer would use that shared DLL
and implement the interface by defining the methods or properties in it.
3>Your app would now load that plugin and cast it to the shared DLL's interface
and then call the desired methods,properties i.e anything that was defined in the interface..
How would your App fetch plugins?
You create a folder
where you would search for the plugins
.This is the folder where others plugins
would be installed
or placed
.
Example
This is your shared dll
//this is the shared plugin
namespace Shared
{
interface IWrite
{
void write();
}
}
The plugin devloper
//this is how plugin developer would implement the interface
using Shared;//<-----the shared dll is included
namespace PlugInApp
{
public class plugInClass : IWrite //its interface implemented
{
public void write()
{
Console.Write("High from plugInClass");
}
}
}
this is your program
using Shared;//the shared plugin is required for the cast
class Program
{
static void Main(string[] args)
{
//this is how you search in the folder
foreach (string s in Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*PlugIn.dll"))//getting plugins in base directory ending with PlugIn.dll
{
Assembly aWrite = Assembly.LoadFrom(s);
//this is how you cast the plugin with the shared dll's interface
Type tWrite = aWrite.GetType("PlugInApp.plugInClass");
IWrite click = (IWrite)Activator.CreateInstance(tWrite);//you create the object
click.write();//you call the method
}
}
}

- 32,393
- 7
- 68
- 89
-
nice done, could you clear me ,for example I developed accounting software by vb.net and I want to add backup feature to take backup from its sql database by adding plugin to my applcation ,so how should I come up with that? – franchesco totti Dec 01 '12 at 10:44
-
@franchescototti you would have to make some changes to your accounting app to implement the plugin search and execute functionality.. – Anirudha Dec 01 '12 at 11:10
-
if you know any sample for windows form app please let me know ? – franchesco totti Dec 01 '12 at 12:10
Use MEF.
The Managed Extensibility Framework (MEF) is a new library in .NET that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed. If you are building extensible applications, extensible frameworks and application extensions, then MEF is for you.
useful link for MEF.
http://www.codeproject.com/Articles/376033/From-Zero-to-Proficient-with-MEF
http://www.codeproject.com/Articles/232868/MEF-Features-with-Examples

- 3,638
- 2
- 28
- 35