none
Interface HELP! RRS feed

  • Question

  • I have:

    1. Interface Library

    2. Plugin Library

    3. Plugin Host library  which is responcisable for loading all of the plugins.

    The Plug-in library loads the plugins is a Singelton and stores them in a .Collection class. This way all of the plugs-ins are available to the entire application.

    To make a long story short i will only post the code that stores each Plug-In / Interface.

    ------------Here is the question----

    Now that i have all of my plug-ins store away in my sweet little singelton ; and ready to server what ever caller. What is the best way to create another instance of the types of Plug-ins that are loaded? For instance; I have a tabPage that holds a plug-in.. This tabPage repersents ONE instance of a product view.. The client will create my Instances of the same Plug-In; however, i only have ONE instance of each plug-in in my Singelton.Collection.

    Here is what i have done and please let me know if this way is ok... For performence reason.. I feel like this might be ok but i just want to make sure..

    -------Here is the object that holds the indivual Plug-ins

    public class AvailablePlugin

    {

    private ISuperPlugin.ISuperPlugin _iPlugin = null;

    private Type _theType = null;

    public ISuperPlugin.ISuperPlugin Instance

    {

    get { return _iPlugin; }

    set { _iPlugin = value; }

    }

    public Type TheType

    {

    get { return _theType; }

    set { _theType = value; }

    }

     

    public ISuperPlugin.ISuperPlugin SendNewType()

    {

    ISuperPlugin.ISuperPlugin newPlugIn = (ISuperPlugin.ISuperPlugin)Activator.CreateInstance(TheType);

    newPlugIn.Host = this.Instance.Host;

    return newPlugIn;

    }

    public override string ToString()

    {

    return Instance.ThePluginType.ToString();

    }

    }

    If you will notice i have tucked the Type in a Property so that i can create an instance of it later on.

    -------------------------------------------(Is this way ok to keep creating instances ?

    public ISuperPlugin.ISuperPlugin SendNewType()

    {

    ISuperPlugin.ISuperPlugin newPlugIn = (ISuperPlugin.ISuperPlugin)Activator.CreateInstance(TheType);

    newPlugIn.Host = this.Instance.Host;

    return newPlugIn;

    }

    -------------------------------------------(Is this way ok to keep creating instances ?

     

    ---I will go ahead and post how i load the object

     

    private void AddPlugin(string pluginAssemblyFile)

    {

    Assembly pluginAssembly = Assembly.LoadFrom(pluginAssemblyFile);

    foreach (Type pluginType in pluginAssembly.GetTypes())

    {

    if (pluginType.IsPublic) 

    {

    if (!pluginType.IsAbstract)  {

    Type typeInterface = pluginType.GetInterface(Plugin.Default.PluginInterfaceBase, true);

    if (typeInterface != null)

    {

    AvailablePlugin newPlugin = new AvailablePlugin();

    Type type = pluginAssembly.GetType(pluginType.ToString());

    newPlugin.TheType = type;

    newPlugin.Instance =

    (ISuperPlugin.ISuperPlugin)Activator.CreateInstance(type);

    newPlugin.Instance.Host = this;

     

     

    //Add the new plugin to our collection here

    this.AvailablePlugins.Add(newPlugin);

    newPlugin = null;

    }

    typeInterface = null; /

    }

    }

    }

    pluginAssembly = null;

    }

     

    thanks for the help!

    erik

    Tuesday, December 5, 2006 6:26 AM

All replies

  • Why is it again that you store the instance as well as the type?

    It's difficult to say if the design is ok, like this. Some kind of schema would be informative.

    Tuesday, December 5, 2006 11:37 AM
  • When i load my plug-ins i store them in a respiratory Singleton. The plug-ins that i have for my app is part of a productManager so i have to keep creating new instances of then plug-ins ( In other words when a new product is defined by the client then of course they go on to create another product- which creates another instance of the plug-in ). The code i posted is when i store the plug-ins after they are loaded. This is also how i assess and recreate new plug-ins from the already loaded plug-ins.

    When i load the plug-ins on first load there is no reason to reload so i store them in the Singelton.. When i need to create another instance of a plug-in I reach into my respority Singelton and create an instance of the already loaded plugin. I am also storing the type for recreating a new instance of the plug-in type... Maybe this is not nessery.

    Which part of the schema do you need?

     

    thanks alot for the help

    erik

     

    Tuesday, December 5, 2006 3:31 PM
  • I can't see why start with one instance of the plugin. Just-in-time creation would have better performance and a smaller footprint. Also you should be cleaning instances up after use, cause if you don't you will end up with a program that just grows until it stops functioning. In real life this means users will have to shut down the application after a certain amount of actions (that create plugin intances).

    The schema I was refering to, would be a picture of what you described in your first post.

    Wednesday, December 6, 2006 7:13 AM
  • Your right i do not see any reason to start an instance eaither.

    I can see that i am going to be on this for at least a month.

    Can you please give me a professional view on the correct way to:

    Client chooses from a list of company types that best describes their company form a ddl.

    Ok client choose Lighting company;;;; now here is where i need to grab the lighting plug-in on the way out the door. AND MAYBE i do not need a plug-in... Maybe i just need to get the .ddl that holds the lighting info ( Looking for your choice of words here... )

    Keep in mind that the GUI is standard for all companies other than those few area that seperate them from each other.. Like a light comapany sell product by the foot, and piece and a Blind comapny sells by Width x Height.. Thats what all of these plugin are.

    Can you tell me the way that you would do this.. "From a professional point of view with the years of experience"

     I have always posted each and every single code that anyone has ever asked for but i can not on this one due to the fact that the way the GUI looks. It's is a one of a kind..

    thanks

    erik

     

    **** Just any elaboration will be great!......

    Saturday, December 9, 2006 2:32 AM
  • Let me first state some things, so that we're clear on the requirements:

    You have different users, who use the same core application to register sales (and maybe other info as well). Some of the screens are different as they describe different products from different type of companies. First of all I would probably choose to split the generic info from the company-specific info as possible (without it becoming a usability problem).

    Then you want the screens that are company specific to be in an external DLL (assembly). You could do this the easy way, by referencing the assembly version independent and just switching out the DLL's for different customers. This is an easy approach, but doesn't allow for a clean select by the user. It just is installed with a different library.

    A more solid approach is to dynamicly load the DLL's. You can then have a static class that describes the DLL to the system (giving the caption, and signing up the screens with a manager inside the core). There should be some kind of manager (a pluginmanager) that has subscription to each screen with the UI commands they should be attached to. All of the classes in the DLL and the pluginmanager (in the core program) should be interface implementations. The interfaces should be in a separate DLL and should be referenced by the core program and all the plugin DLL's.

    If you have more questions about this then let me know.

    Monday, December 11, 2006 7:58 AM