Skip to content
NLNuvyntra Labs

Documentation

Dependency injection

AddMvvmExpress and UseMvvmExpress, 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 MAUI app calls UseMvvmExpress, which registers Core services, replaces IMainThread with MauiMainThread, marshals command/property notifications, and auto-attaches ViewModelLifecycleBehavior.

builder
    .UseMauiApp<App>()
    .UseMvvmExpress(o => o
        .UseNavigationPage()
        .UseDialogs()
        .UseAuth<LoginViewModel>());
// optional catalog path:
// .UseMvvmExpress(o => o.UseShell().UseDialogs().UseAuth<LoginViewModel>());

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

UseNavigationPage is the login → replace-root → push host. UseShell is optional. UseDialogs lives in the Dialogs package. MvvmExpressOptions also has CancelOperationsOnDisappear, EnableDiagnostics, MarshalNotifications (default true), AutoAttachLifecycle, ConfirmDirtyNavigation, ForwardNavigationFailures, and ApplyGeneratedRegistrations. Call InitializeComponent() on App before resolving pages. Do not mix MAUI MainThread statics in ViewModels.

What AddMvvmExpress registers

AbstractionDefaultTypical app replacement
IMessageHubMessageHubKeep
IBusyGateBusyGateKeep
IErrorSinkNullErrorSinkApp logger sink
ICache / ICachedFetcherMemoryCache / CachedFetcherPlugin.Maui.ApiCache adapter
IConnectivityProbeInMemoryConnectivityProbePlugin.Maui.NetworkMonitor adapter
IOperationExecutorOperationExecutorKeep
IViewModelScopeFactoryServiceViewModelScopeFactoryKeep
IFeatureSwitchMemoryFeatureSwitchPlugin.Maui.FeatureFlags adapter
IStateStoreMemoryStateStoreApp persist store
IWindowContextWindowContext.DefaultMauiWindowContext.Current
IWindowNavigatorRegistryWindowNavigatorRegistryKeep; register per window
INavigator / IPageNavigatorInMemoryNavigatorUseNavigationPage() / UseShell()
IMainThreadImmediateMainThreadMauiMainThread (host)
IDialogs / INotifierNullDialogsUseDialogs() → MauiDialogs / MauiNotifier
IAuthStatenot registeredUseAuth + Plugin.Maui.SecureSession adapter
IAccountServicenot registeredApp register / reset adapter

Replace defaults in the MAUI host

UseNavigationPage / UseDialogs replace the in-memory defaults. UseAuth<TChallenge>() wraps GuardedNavigator when screens require a session — do not RemoveAll and reconstruct the guard. Do not register UseShell and UseNavigationPage together unless you really have two hosts.

builder.UseMvvmExpress(o => o
    .UseNavigationPage((nav, _) => nav
        .Map<LoginViewModel, LoginPage>("login")
        .Map<ChatHostViewModel, ChatHostPage>("chats"))
    .UseDialogs()
    .UseAuth<AuthLoginViewModel>());

services.AddSingleton<IAuthState>(sp =>
    new SecureSessionAuthState(sp.GetRequiredService<ISecureSession>()));

services.RemoveAll<IPageNavigator>();
services.AddSingleton<IPageNavigator>(sp =>
    new MauiPageNavigator(MauiWindowContext.Current, sp)
        .Map<PageStackViewModel, PageStackPage>("stack"));