Add-In Like feature required RRS feed

  • Question

  • Hi All,

    I have scenario where I need to have a Add-In like feature in a an window application ( c#). The user selects a add-in ( dll ) and relevant menus are added to existing menu. How can I achieve this ?

    Thanks you all for your inputs.

    Thursday, February 21, 2008 2:32 AM


  • One way you could do this, and I'd imagine that there are plenty of ways, would be to use a provider / strategy pattern. 


    This works by having a class that implements an interface, or derives from an abstract class (I prefer interface personally, in most cases).


    So you could have an interface INavDeepsAddIn, then have one or more implemented classes that implement that interface.  Each implementation would define, or do something, such as adding menu functionality, or possibly simply providing data that the calling class can use to merge the menu with the current one.  I haven't thought yet how you would do that, although I did do that a good few years back, and if I remember correctly, it is something along the lines of a .Merge method on the menu class, dont' quote me though; ask google!


    You could then use a factory class that would read a configuration, which would list a fully specified type name, you know in the form of "MyNamespace.MyClass, MyLibrary, Version=, Culture=neutral, PublicKeyToken=xxxxx", and those assemblies would either be in the application folder, or in the GAC.  You might want a name and description just for your own sanity too in there.

    The factory class would then cycle through each entry, and use:


    Type objectType = Type.GetType(providerName, true, true);


    INavDeepsAddIn addIn = Activator.CreateInstance(type, .....); // or type.GetConstructor( .... ) ... being binding params and parameter list definitions


    Then, if for example your interface has a method Setup() you can call




    And that code would do whatever it needs to do, or provider whatever data it needs to provide to allow you to merge menus, add toolbars, or whatever you desire.


    I hope this helps you, it's fairly long winded, and it's totally from memorry, so I apologise if it's not exactly right, but the concepts are all present, and with the help of your favourite search engine, you should be able to learn more, and completel the picture.


    Good luck,


    Martin Platt.

    Thursday, February 21, 2008 9:06 AM