Developing a plug-in type application

  • Thread starter Thread starter Sinex
  • Start date Start date
S

Sinex

Hi,
I want to build an application that triggers different algorithms. The
algorithms will be developed as class libraries over a period of time. I
want to just plug-in these libraries as and when they get developed. The
'interface' for all the algorithms will be same...only the implementation
keeps changing. The main application will make a decision at run time (based
on some parameters) as to which algorithm to use.
I want it to work this way:
1. I specify which library (algorithm) to use in the config file.
2. The application should load the corresponding library and call
the methods in it.
3. When a new algorithm is developed, I want to just add the
library(dll) to the GAC and add an entry in the config file...and the
application should be able to load this new dll if needed at run time.

I have some vague idea that this has to do with Reflection...but am not
able to get started. Will appreciate any comments on the design too...if
there are some standard patterns etc.


....Sinex.
 
Sinex,

Here's the easiest way I can think of:

* Define an interface
* Make your plugins implement it
* Create an instance of plugin at runtime using Activator class:

Type pluginType = Type.GetType("MyPlugin, MyPlugin"); // the can come from a
confing file.
IPlugin plugin = (IPlugin)Activator.CreateInstance(pluginType);

Few notes:
Read documentation on Type.GetType(string) carefully.
You might want to load plugins into a separate AppDomain, so they can be
unloaded when not needed.

HTH,
Alexander
 
See thes links:

Creating a Plug-In Framework
http://msdn.microsoft.com/asp.net/c...library/en-us/dnaspp/html/pluginframework.asp Search Dynamically for Plug-Ins http://msdn.microsoft.com/asp.net/c...y/en-us/dnaspp/html/searchforplugins.asp----- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalikDisclaimer: Opinions expressed in this forum are my own, and notrepresentative of my employer. I do not answer questions on behalf of my employer. I'm just aprogrammer helping programmers.--"Sinex" <[email protected]> wrote in messageHi,> I want to build an application that triggers different algorithms. The> algorithms will be developed as class libraries over a period of time. I> want to just plug-in these libraries as and when they get developed. The> 'interface' for all the algorithms will be same...only the implementation> keeps changing. The main application will make a decision at run time(based> on some parameters) as to which algorithm to use.> I want it to work this way:> 1. I specify which library (algorithm) to use in the config file.> 2. The application should load the corresponding library and call> the methods in it.> 3. When a new algorithm is developed, I want to just add the> library(dll) to the GAC and add an entry in the config file...and the> application should be able to load this new dll if needed at run time.>> I have some vague idea that this has to do with Reflection...but am not> able to get started. Will appreciate any comments on the design too...if> there are some standard patterns etc.>>> ...Sinex.>>
 
I have no idea why the formatting was so tossed.

Trying again...

Creating a Plug-In Framework
http://msdn.microsoft.com/asp.net/c...y/en-us/dnaspp/html/pluginframework.aspSearch Dynamically for Plug-Inshttp://msdn.microsoft.com/asp.net/community/authors/royosherove/default.aspx?pull=/library/en-us/dnaspp/html/searchforplugins.asp----- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalikDisclaimer: Opinions expressed in this forum are my own, and notrepresentative of my employer. I do not answer questions on behalf of my employer. I'm just aprogrammer helping programmers.--
 
Back
Top