Jump to content

Program Plugins

- - - - -

  • Please log in to reply
2 replies to this topic

#1
PGP_Protector

PGP_Protector

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 253 posts
I'm getting ready to start a new application.
It will simply read a File (First iteration will be CVS formated files)
then control some external hardware (brand x for now)

Now what I'm wondering is / are their any good examples on how to add a "Plug In" feature to an application. For example you can add "Filters" to Photoshop or tools to Import New Files types.

So my Import Plugin would by default open the CVS File, process it and return the data in a structured format to the main application.

But next month I might need it to open a new file format, and instead of patching / releasing a new version of the software I'd want to just allow a new plugin to be installed.

This would then open the new file format, convert it & return the data to the main application in the standardized format.

#2
sam_coder

sam_coder

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 372 posts
Yes, you can do this. It works basically by creating a Class Library, that implements the functionality you wish for the plugin.
The trick is how you choose to implement it.

If you want the input filter to be explicitly configured, one great way to do this is to use a dependency injection runtime like Microsoft Unity.patterns & practices - Unity

A more cowboyish approach, would be to just reflectively load up your 'plugins'. (like literally scan a directory to dll files, and attempt to load them up as assemblies into an App Domain)

In any case, you're dealing with a situation where you would want to create an interface for your import plugin's to implement.

you want to end up with something like this.



interface IImporter {

   bool import(string source);

}




so that you can say...



IImporter dynamic_importer = get_import_plugin();



The whole thing can work really well if you do it right. But remember that the plugins will have a dependency to whatever you compile them against. There are situations where even though you might wish to patch one item, rebuilding one could cause another to need to be rebuilt.

#3
rbenhassine

rbenhassine

    Newbie

  • Members
  • Pip
  • 1 posts
There is a more simple way : MEF for Managed Extensibility Framework.
Here is a link : MEF on CodePlex




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users