Multiple instances of the same add-in

Jan 26, 2009 at 3:59 PM
Hi all!

Using Kent Boogaart's most excellent blogg MAF Gymnastics: Service Provider, I have created the following scenario.
I have an "empty" host, containing a large white space for user controls to show up.
I have two types of add-ins, the "services" which acts as a form of datasource, and the "consumers", which acts as UI presentation of the data obtained from the services.
The difference from Kent's code, is that my "consumers" are UserControls, add-ins inheriting the INativeHandleContract. I've also added some events in the service for the consumer to handle, among other things.

Now, my problem is that I want to have multiple instances of the same "consumer" add-in (UserControl), without activating the add-in multiple times. Activating a visual add-in already takes 6mb memory (WPF UserControl)... When activating the add-in, I get a newly created instance of the object, ready to use, but I want to have many instances of this object, without having to activate the add-in many times.

Is it possible for me to "duplicate" that (e.g. execute its parameterless constructor to obtain another object of the same type), or is there a more preferred way of doing it?? I thought about adding a "factory" in the add-in, which then would be the object created upon activation, and from there create instances of the UserControl I need, but I figured it'll eventually break Kent's scenario (eventually I will want to do this to my "services" as well, and when the "consumer" asks the host for a "service" I don't want it to receive the "factory").

For a more understandable scenario
Lets say for instance I have three services, each serving data to be presented in some way. I now have one UserControl add-in, from which I want three identical user controls (one for each service). But I don't want to activate the add-in three times...