AddIns, contracts and multiple interfaces

Jul 25, 2008 at 1:09 PM
This topic somewhat related to earlier discussions I have seen here.

What I would like, is to have a base contract that all addins implement. E.g. IBaseContract.
Then I would like to create one or more specialized contracts. E.g. IProcessFile, IPrintFile etc.

I would like to use these contracts when implementing an addin, so the addin would e.g. look like this.

public class PrinterAddIn : IBaseContract, IPrintFile
    public void Initialize(){} // from IBaseContract
    public void PrintFile(string filename){} // from IPrintFile

Later when I want to discover my addins, I find all addins based on the IBaseContract, activates and calls Initialize, and keeps a reference to the activated addin. Later when I decide to use the PrinterAddin, I want to take the common IBaseContract reference and make use of IPrintFile (as the instance of the addin actually implements its interface).

Now reading a previous post, it is stated that addins cant implement more than one contract (if I understood correctly). If so, how are we to take use of the IServiceProviderContract and IProfferServiceContract in one addin? The documentation says the following (taken from IProfferServiceContract documentation): "Components typically implement IProfferServiceContract on the same type on which they implement IServiceProviderContract" i.e. an addin implements both contracts. I would appreciate if someone could elaborate more on this, and even give some samples if available.

Jul 25, 2008 at 3:28 PM

I believe the previous post was saying that it was not possible to have multiple pipelines between the host and same instance of an add-in. So if your add-in implements multiple contracts you will get the pipeline appropriate to the view you supply to AddInToken.Activate<T>().

It sounds like what you want is a base interface that defines some common functionality, and then you want to specialize that for specific add-ins. That is most certainly supported and I have done it myself.

For example, I have had the following:
 - Contracts: IAddInContract, IApplicationAddInContract (extends IAddInContract), IServiceAddInContract (extends IAddInContract)
 - Views: IAddIn, IApplicationAddIn (extends IAddIn), IServiceAddIn (extends IAddIn)
 - Adapters: BlaToBlaAdapter_IAddIn (abstract class), BlaToBlaAdapter_IApplicationAddIn (extends BlaToBlaAdapter_IAddIn) BlaToBlaAdapter_IServiceAddIn (extends BlaToBlaAdapter_IAddIn)

The host would find and activate add-ins via the host's IAddIn view. It could then cast those add-ins to IServiceAddIn or IApplicationAddIn according to the actual add-in type. The add-in implementation would look like:

public class SomeAddIn : IApplicationAddIn


All works fine.