Can one add-in implement multiple contracts?

Jul 23, 2008 at 9:10 PM

I am guessing the answer to this is no, but I'm hoping:

Suppose I have two separate add-in contracts:

    [AddInContract]
    public interface IAddIn1
    {
         void Notify1();
    }

    [AddInContract]
    public interface IAddIn2
    {
        void Notify2();
    }


In my host app, I will activate both types of add-ins, and when something happens, call the method on one or the other class.

I would like to be able to define an add-in class that implements both interfaces.  When I activate, I would like only one object of that class to be created; in the pipeline, it would need two different sets of adapters, so I guess I would need to activate addins of both types, IAddin1 and IAddIn2.

Is there any way to do this?  I can detect that the class implements both interfaces and only activate it once, but that only creates one set of adapters through the pipeline.


Thanks,
Bob Wall


Jul 24, 2008 at 3:19 AM
Hi BobWall,

We don't support activating an add-in using two different contracts, but you can do one of the following:
  • Re-adapt the object after activation. This might not work for you, as you need a reference from one of your contracts to the other:
    [AddInContract]
    public interface IAddIn1Contract
    {
         void Notify1();
         IAddIn2Contract AsAddIn2();
    }

    [AddInContract]
    public interface IAddIn2Contract
    {
        void Notify2();
    }

Aug 25, 2008 at 11:46 PM

Is this an enhancement that would be considered for the add-in framework?  We're trying to define a set of interfaces against which users can write add-ins, and it's pretty limiting to try to enumerate all the possible combinations that would be supported.

I guess that an overload to AddInToken.Activate<T> might be required to indicate that the host and add-in side adapters should be created, but that the add-in side adapter should re-use an existing add-in object that implements the second interface.


Thanks,
Bob

Aug 26, 2008 at 8:42 AM
Hi Bob,

Another approach is to use ContractAdapter. If you add the ability for the host to obtain the MBRO object implementing the add-in (ie. the add-in side adapter), then you can use ContractAdapter to adapt it into another add-in contract.

HTH,
Kent