Nexus-Mods / NexusMods.App

Home of the development of the Nexus Mods App
https://nexus-mods.github.io/NexusMods.App/
GNU General Public License v3.0
608 stars 40 forks source link

Add Event Bus #1537

Open erri120 opened 3 weeks ago

erri120 commented 3 weeks ago

An event bus fixes the issue of having unrelated components try to talk with each other.

We should discuss what kind of API we want.

Al12rs commented 3 weeks ago

This came up during discussion of how to best handle things like Advanced Installer, that would otherwise cause circular dependencies.

Other issue is backend needing to show some kind of UI interaction, e.g. download link handler needs to show a Message dialog in case user is not logged in.

erri120 commented 3 weeks ago

While we can probably use something like MediatR, it's very complex and does a ton of other stuff. The ReactiveUI Message Bus already exists, however the API has some major downsides, mainly that you need to register a "source" observable stream:

MessageBus.Current.RegisterMessageSource(/* ... */);

This is undesired, because it would require every message producer to create and register a subject, and take care of the disposable, even if they only want to send a single message. Although the helper method MessageBus.Current.SendMessage has better ergonomics, the implementation leaves much to be desired (https://github.com/reactiveui/ReactiveUI/blob/main/src/ReactiveUI/Routing/MessageBus.cs#L131-L148).

Another issue that the ReactiveUI message bus has, is not being able to "wait" for a response. SendMessage returns void because messages can be scheduled using different schedulers.

LukeNexusMods commented 2 weeks ago

Easy to get in, will help with the creation of modals and things that notify the user. A time saver. Enables us to do more things.