Uno Platform
The Uno Platform is an Open-source platform for building single codebase native mobile, web, desktop, and embedded apps quickly.
With Uno Platform + Mediator, your pages and view models can handle events without being registered in dependency injection, handlers marked [MainThread] run on the UI thread,
and you get all of the offline, persistent cache, and other app-building middleware.
Visit their website and documentation for more details.
- Install
to your project.
- In your
App.xaml.csfile, register the mediator on the Uno application builder:protected override async void OnLaunched(LaunchActivatedEventArgs args){var builder = this.CreateBuilder(args).AddShinyMediator(cfg => cfg.AddUnoPersistentCache()).Configure(host => host// your other host configuration);MainWindow = builder.Window;Host = await builder.NavigateAsync<Shell>();}AddShinyMediatoron the application builder also handsbuilder.Windowto the mediator. The window is needed for the event collector, error dialogs, and[MainThread]. - Start making calls to the mediator as you normally would.
Without Uno.Extensions hosting
Section titled “Without Uno.Extensions hosting”If you build your own service collection, pass your window to UseUno:
services.AddShinyMediator(cfg => cfg.UseUno(MainWindow));If you only have an IHostBuilder, host.AddShinyMediator() registers everything, but no window is tracked. Add it yourself once it exists:
Host.Services.GetRequiredService<UnoWindowTracker>().Add(MainWindow);Use the same call for any secondary window that should take part. A window stops being tracked when it closes.
Event Collector
Section titled “Event Collector”UseUno installs the Uno event collector. When an event is published, the collector walks the visual tree of every tracked window, including open popups,
on the UI thread. Any FrameworkElement, or its DataContext, that implements IEventHandler<TEvent> takes part in the publish.
A view model shared by many elements is called once.
public partial class MainViewModel : ObservableObject, IEventHandler<OrderShipped>{ [MainThread] public Task Handle(OrderShipped @event, IMediatorContext context, CancellationToken ct) { this.Status = $"Order {@event.OrderId} shipped"; return Task.CompletedTask; }}A publish from a background thread waits up to 5 seconds (UnoEventCollector.UiThreadTimeout) for the UI thread to collect handlers. If the UI thread is
blocked, view handlers are skipped and a warning is logged.
Middleware Support
Section titled “Middleware Support”The Mediator Uno Platform extension installs default middleware, which you can opt out of. To skip it, pass false for
includeStandardMiddleware (UseUno(false) or AddShinyMediator(includeStandardMiddleware: false)).
- Main Thread - runs on the tracked window’s
DispatcherQueue - User Notification Errors - shown in a
ContentDialogon the main window - Offline
- Replay Stream
- Persistent Caching - call
AddUnoPersistentCache(); files are stored inApplicationData.Current.LocalFolder
Connectivity Broadcaster
Section titled “Connectivity Broadcaster”Publishes a ConnectivityChanged event whenever internet availability changes (from NetworkInformation). It requires Uno.Extensions hosting,
which initializes it once the host is built.
builder.AddShinyMediator(cfg => cfg.AddConnectivityBroadcaster());
public partial class MyViewModel : Shiny.Mediator.IConnectivityEventHandler{ [MainThread] public Task Handle(ConnectivityChanged @event, IMediatorContext context, CancellationToken ct) { this.IsOnline = @event.Connected; return Task.CompletedTask; }}Replacing Infrastructure
Section titled “Replacing Infrastructure”Every infrastructure service is registered with TryAdd. To replace one, register your own before calling UseUno.
| Service | Default |
|---|---|
IMainThreadDispatcher |
UnoMainThreadDispatcher (window DispatcherQueue) |
IAlertDialogService |
AlertDialogService (ContentDialog) |
IInternetService |
InternetService (NetworkInformation) |
IStorageService |
StorageService (ApplicationData.LocalFolder) |

