-1

Possible Duplicate:
Writing C# Plugin System

Is it possible to write a program that accepts plug-ins?

My program should check a folder where some DLLs are copied, then look into those files and get witch parameters the main program has pass to the functions contained by those DLLs.

I'm writting a program that checks for new job opportunities in some Webs and it would be perfect if the function for reading each web is contained in a different URL. If that is possible, updating the program when those Webs change would be so easy.

Community
  • 1
  • 1
Jaime Oro
  • 9,899
  • 8
  • 31
  • 39
  • 1
    Search the stackoverflow and google...you might also find this interesting http://www.johnkoerner.com/index.php?/archives/43-Creating-a-Plugin-Architecture-in-C.html – Saif Khan Feb 11 '11 at 23:03

2 Answers2

3

Yes.

This is how systems like MEF work.

As you've tagged the question c# I'll use these terms but you can do it with any language as long as you can load a dll and interrogate it.

You create a framework that looks for assemblies that expose certain interfaces. If they exist load them.

To create a plugin implement the required interfaces and put the dll into the location where it will be found.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
2

It's absolutely possible. There are different ways of doing it.

One way is to create an interface, eg IPlugin which may have an init (setup, register plugin etc), execute (run command, pass parameters, return value), and unload method.

Alternatively you could have a PluginAttribute you could put on your class/method to tell the C# app it is a plugin.

The app could use reflection and find plugin classes in the assembly.

Russell
  • 17,481
  • 23
  • 81
  • 125