none
Is it possible to create an add-in with MAF that implements two or more contracts / AddInViews? RRS feed

  • Question

  • Creating add-ins to isolate functionality using MAF is straightforward, albeit with a lot of boilerplate to be written. Now, I am at a point where I have several contracts, each describing a part of the interface, and I want an add-in that implements two or more of these contracts (and add-in views).

    When trying to implement it straight, i.e., writing AddInViews, AddInSideAdapters, HostViews and HostSideAdapters for the individual contracts, and then having the add-in implement two or more AddInViews, the AddInStore.FindAddIns method only wires up the one pipeline given with FindAddIns. I could evaluate multiple collections of tokens for the other HostView classes, but activating the token would give me new instances each time.

    Currently, I am working around this by defining my interfaces without extending IContract, and defining multiple contract interfaces which extend the respective interfaces so I have a contract and all the additional boilerplate for each constellation of interfaces that appear in my program. Since this means having 2^n contracts, AddInVies, HostViews, AddInSideAdapters and HostSideAdapters and having to query the add-in store 2^n times when I have n interfaces in the worst case, I want to know if there is a better solution to this.

    Wednesday, September 28, 2016 1:31 PM

Answers

  • I feared this already. But I will resort to another smaller but not less hackish approach:

    • Have one large "God Interface" including contract, views, adapters etc., which has ALL the things I need for everything
    • This interface has some boolean properties that denote which parts are used and which not
    • The add-in on the other side implements this "god interface" and delegates all necessary calls to the "real" worker nobjects which are then implemented in a cleaner way

    To avoid having to implement the interface completely, I will create an abstract "AddInBase" class that implements everything as "virtual" but all the bool properties return false and all methods throw exceptions. So I can override only what I need for my add-in.

    Thursday, September 29, 2016 7:19 AM

All replies

  • Hi Windfisch,

    Thank you for posting here.

    >>Since this means having 2^n contracts, AddInVies, HostViews, AddInSideAdapters and HostSideAdapters and having to query the add-in store 2^n times when I have n interfaces in the worst case, I want to know if there is a better solution to this.

    Based on my search. I cannot find a better solution to solve it. I think you need to store 2^n times.

    Here is related document.

    https://msdn.microsoft.com/en-us/library/bb384201(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/system.addin.contract.icontract(v=vs.110).aspx

    https://msdn.microsoft.com/en-us/library/system.addin.contract.icontract.querycontract(v=vs.110).aspx

    I hope the message will help you.

    ---if your issue has been resolved, please mark it.

    Best Regards,

    Hart


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.

    Thursday, September 29, 2016 2:33 AM
  • I feared this already. But I will resort to another smaller but not less hackish approach:

    • Have one large "God Interface" including contract, views, adapters etc., which has ALL the things I need for everything
    • This interface has some boolean properties that denote which parts are used and which not
    • The add-in on the other side implements this "god interface" and delegates all necessary calls to the "real" worker nobjects which are then implemented in a cleaner way

    To avoid having to implement the interface completely, I will create an abstract "AddInBase" class that implements everything as "virtual" but all the bool properties return false and all methods throw exceptions. So I can override only what I need for my add-in.

    Thursday, September 29, 2016 7:19 AM