I am experimenting with the System.Addin MAF capability. I have a host that creates an instance of a new addin in a new appdomain and starts it running.
I'd like to have the addin call methods on the host to pass data back up. It is clear how to have the host create an instance of the addin (AddinToken.Activate), but how does the addin get a reference to the host?
I have tried passing a copy of the host down to the addin through an Initialise method, but because it needs to be serializable, this causes difficulties. I have to mark some properties as NonSerialized which mean they are null when the addin calls the methods on it. I get the feeling that although there is a View & Adapter written to support the Addin->Host contract, it is being bypassed by this method?
You don't pass a copy of the host down to the addin. Rather you need to define an interface that you pass to the addin and provide an implementation on the host side.
For example, you could define an Initialize
method that the AddIn has to implement. You could specify parameters to that method that represent services provided by the host. One case where I use this is to provide a logging interface to the addin. The initialize method is defined as:
void Initialize(ILogger logger);
When the host calls initialize on the AddIn, it passes an implementation of ILogger that the Addin can then hold onto and call whenever it needs to log.