There are two .net Add-ons. Both are IDockableScreens. What is the cleanest way to communicate between both add-ons ? I thought about events at the beginning, but to register for events of the other add on, you need an instance of the add on which fires the event. Is there a way to access the add-on instances?
Or is it a common way to realize an event broker via an IPlugin project to handle the event handling?
You could use IEventAggregator which you can import, implement IHandle<T> and subscribe to the aggregator to get messages of type T.
However, I would just define some interface IMyInterface in one of the add-ons and export a shared instance of it, then just import that in the other add-ons.
So something like this (example only, written from memory):
public interface IMyinterface
{
// Add some useful properties and methods.
}
[Export(typeof(IDockableScreen))]
[Export(typeof(IMyInterface))]
[PartCreationPolicy(CreationPolicy.Shared)]
internal class MyDockable : Screen, IMyInterface
{
// Implement.
}
[Export(typeof(IDockableScreen))]
internal class MyOtherDockable : Screen
{
[ImportingConstructor]
public MyOtherDockable(IMyInterface myDockable)
{
// Do something with the other dockable.
}
}
If you want to do some kind of plugin system of your own, you can have many implementations of some interface exported and [ImportMany] them, or use IoC.GetAll<T>()