Skip to content
NLNuvyntra Labs

Documentation

Messaging

IMessageHub: weak subscribe by default, recipient-first handlers, and when to use a command or a service instead.

IMessageHub

IMessageHub is the in-process pub/sub for ViewModels that should not hold each other. Default subscribe is weak. The handler signature is Action<TRecipient, TMessage> so the delegate receives the subscriber as an argument and does not capture this. Strong subscribe is explicit and you own Unsubscribe / Dispose.

hub.Subscribe<HomeViewModel, CartChanged>(
    this,
    static (vm, _) => vm.Refresh(),
    weak: true);

hub.Publish(new CartChanged(productId));

When not to use the hub

  • Parent → child work that has a clear owner: inject a service or call a method.
  • Navigation: use INavigator, not a “please open details” message.
  • Auth gates: GuardedNavigator + IAuthState, not a login broadcast as the only lock.
  • High-frequency sensor ticks: a typed service or AsyncState, not a message per sample.