Skip to content
Nuvyntra Labs

Documentation

Dependency injection

AddMvvmExpress and UseWinUIMvvmExpress, what the host registers, and how the app replaces navigators and dialogs.

Host registration

MVVMExpress uses Microsoft.Extensions.DependencyInjection only. There is no DryIoc, Unity, or Grace package. Shared libraries and tests call AddMvvmExpress. A WinUI 3 app calls UseWinUIMvvmExpress, which registers Core services, replaces IMainThread with DispatcherQueueMainThread, maps IWindowContext to WinUIWindowContext, marshals command/property notifications, and auto-attaches Loaded / Unloaded lifecycle.

builder.Services.UseWinUIMvvmExpress(o => o
    .UseFrameNavigation((nav, _) => nav
        .Map<LoginViewModel, LoginPage>("login")
        .Map<HomeViewModel, HomePage>("home"))
    .UseDialogs()
    .UseAuth<LoginViewModel>());

// net10.0 tests / shared ViewModel projects
services.AddMvvmExpress();
services.AddAuth<LoginViewModel>();

UseFrameNavigation is the login → replace-root → push host. There is no UseShell. UseDialogs lives in the Dialogs package. AddModule<T>() registers a feature assembly. MvvmExpressOptions also has CancelOperationsOnDisappear, EnableDiagnostics, MarshalNotifications (default true), AutoAttachLifecycle, ConfirmDirtyNavigation, and ForwardNavigationFailures.

What AddMvvmExpress registers

AbstractionDefaultTypical app replacement
IMessageHubMessageHubKeep
IBusyGateBusyGateKeep
IErrorSinkNullErrorSinkApp logger sink
ICache / ICachedFetcherMemoryCache / CachedFetcherApp HTTP cache
IConnectivityProbeInMemoryConnectivityProbeApp probe
IOperationExecutorOperationExecutorKeep
IViewModelScopeFactoryServiceViewModelScopeFactoryKeep
IFeatureSwitchMemoryFeatureSwitchApp flags
IStateStoreMemoryStateStoreApp persist store
IWindowContextWindowContext.DefaultWinUIWindowContext.Current / For(Window)
IWindowNavigatorRegistryWindowNavigatorRegistryKeep; register per window
INavigator / IPageNavigatorInMemoryNavigatorUseFrameNavigation()
IMainThreadImmediateMainThreadDispatcherQueueMainThread (host)
IDialogs / INotifierNullDialogsUseDialogs() → WinUIDialogs / WinUINotifier
IAuthStatenot registeredUseAuth + app IAuthState

Feature modules

IModule / AddModule<T>() is a thin composition boundary. A feature assembly registers its own routes, ViewModels, and services. It is not a Prism region catalog.

public sealed class CatalogModule : IModule
{
    public void Configure(IServiceCollection services)
    {
        services.AddSingleton<ICatalog, Catalog>();
    }
}

builder.Services.AddModule<CatalogModule>();

Discussion

Comment on Plugin.WinUI.MVVMExpress. The thread lives on this component's GitHub repository (nuvyntralabs/Plugin.WinUI.MVVMExpress). Sign in with GitHub — Giscus uses Discussions, Utterances uses Issues.