# Communication between several add-ons

**URL:** <https://forum.visualcomponents.com/t/communication-between-several-add-ons/6397>\
**Category:** .Net Add-on Programming\
**Created:** [April 17, 2024, 4:55pm UTC](https://forum.visualcomponents.com/t/communication-between-several-add-ons/6397 "2024-04-17T16:55:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MG95](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@MG95](https://forum.visualcomponents.com/u/MG95)\
**Post date:** [April 17, 2024, 4:55pm UTC](https://forum.visualcomponents.com/t/communication-between-several-add-ons/6397/1 "2024-04-17T16:55:47Z")

</div>

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?

All suggestions welcome 🙂

---

<div class="post-metadata">

**Author:** ![TSy](https://forum.visualcomponents.com/user_avatar/forum.visualcomponents.com/tsy/32/761_2.png) [@TSy](https://forum.visualcomponents.com/u/TSy)\
**Post date:** [April 17, 2024, 7:48pm UTC](https://forum.visualcomponents.com/t/communication-between-several-add-ons/6397/2 "2024-04-17T19:48:23Z")

</div>

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):

```python
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>()`

---

<div class="post-metadata">

**Author:** ![MG95](https://forum.visualcomponents.com/letter_avatar_proxy/v4/letter/m/ccd318/32.png) [@MG95](https://forum.visualcomponents.com/u/MG95)\
**Post date:** [April 18, 2024, 5:37pm UTC](https://forum.visualcomponents.com/t/communication-between-several-add-ons/6397/3 "2024-04-18T17:37:19Z")

</div>

> [@TSy](#):
>
> IEventAggregator

Thanks, the variant with the interface works well for my use case. Thank you for the quick support.
