Hi there.
I have no idea but had a sudden urge to ask about things like this, I guess its good for the knowledge!
I have an app created in .NET 1.1
I *may* wish to implement plugin's with the application, so developers can create their own plugin's for the application.
Question 1) If a plugin was created in .NET 2.0, will it still work with the .NET 1.1 application (obviously assuming they have both frameworks installed)
Question 2) How would one go about creating plugin's for their application
Question 3) Is it possible for this plugin to implement/"subscribe" to public events exposed by my application, so when I raise an event, any of the plugin's who have a subscription to the event, is notified
That's it for now :)
Many thanks!

custom plugin questions!
Spenceee
awj100
ok I have some more Q's
how can I hook/raise an event to the plugin's that have been loaded
the plugin's that have been loaded are in a collection.
each plugin implements/includes an interface IPlugin.
IPlugin has a few delegates/events
When loading/instantiating the plugin's, how can I initialize/establish events, so if I raise an event in my application, which is included in the interface, that it will call/raise the events to the other plugins that have been loaded
Nawar G.
pc0416
I hope I can help answer some of your questions or point you in the right direction.
Question 1:
I do not believe that plugins would work with mixing 1.1 and 2.0. I am not exactly sure on this as I have not tried it but that is my guess until I try it.
Question 2 and 3:
One of the easiest ways to support pluggins is by implementing Interfaces. For example, you could implement an IPlugin interface that describes events, methods, and properties the plugins must implement. This is where Polymorphism is at its best. Here is an example. You could create an interface that defines the following methods and events:
Interface IPlugin
event Remove_Item(sender as Object, e as eventargs)
sub DisplayMessagebox(text as string)
End Interface
Then you would require all of your plugins to implement this interface. Your main application could then use reflection or Activator.Createinstance to create an instance of your plugin and then call the corresponding methods or react to the events. There are a few different articles out there describing in much more detail the specifics but this is the general idea that can be used to create a plugin architecture. I hope this helps.
Mark Dooley
Thank-you
I do apologize, still trying to grasp this.
I think I have everything except for the implementation of events/delegates.
interface:
public delegate void SomeMessage(string theMessage);
public interface IPlugin
{
string PluginDescription { get; }
void DoInitialize();
event SomeMessage OnEventSomeMessage;
}
a plugin
//implements the interface IPlugin
void DoInitialize()
{
//what do I need to do here for creating the events in this plugin
}
MainApp
public delegate void SomeMessage(string theMessage);
public event SomeMessage OnEventSomeMessage;
....
this.OnEventSomeMessage += new SomeMessage(MainForm_OnEventSomeMessage);
....
//loading plugins
IPlugin thePlugin = (IPlugin)Activator.CreateInstance(theTypeOfPlugin);
//here, how do I wire up/create the events of the plugins to "link" up to this main application
thePlugin.DoInitialize();
this.theCollectionOfPlugins.Add(thePlugin);
I hope that makes sense. I have been following you're generous code however somethings I don't quite understand, like the IApplication interface and such.
I hope you can help me using this code I have about where to place the events, how to make them work/instantiated and how to call the events for each plugin I have loaded, and placed in the collection.
Rudemusik
Many thanks, yes I had eventually got that there had to be a "link" to the plugin for it to "talk" to the main app.
I still cannot seem to get the events to be hooked up to the main app (host)
Patrick Sears
namespace
Program{
public interface IApplication{
event EventHandler ApplicationEvent;}
public class Application : IApplication{
#region
IApplication Members public event EventHandler ApplicationEvent;#endregion
public void FireEvent(){
ApplicationEvent(
this, EventArgs.Empty);}
}
public interface IPlugin{
void Initialize(IApplication application);}
public class APlugin : IPlugin{
#region
IPlugin Members public void Initialize(IApplication application){
application.ApplicationEvent +=
new EventHandler(OnApplicationEvent);}
void OnApplicationEvent(object sender, EventArgs e){
Console.WriteLine(
"Handled application event.");}
#endregion
}
public class Program{
static void Main(){
Application app =
new Application(); IPlugin plugin = (IPlugin) Activator.CreateInstance(Type.GetType("Program.APlugin"));plugin.Initialize(app);
app.FireEvent();
}
}
}
KnobCreek
Thanks! I was aware about interfaces and so on but never actually used it.
cool! you have been most helpful!
Mitch Walker - MSFT
Timeware
tomjohnr
Thanks.
is there any chance of a sample/example as I am new to this stuff :)