.NET MAUI › Best Practices & Architecture

How do you keep a MAUI codebase testable and loosely coupled?

Advanced

Answer

Depend on interfaces (services, navigation, dialogs, device features) injected via DI; keep view models free of platform and UI types; use the MVVM Toolkit for commands/observables; and put integration-heavy code behind seams you can fake. Aim for the bulk of behavior to be unit-testable without a device.
public OrdersViewModel(IOrderService svc,
    INavigationService nav, IDialogService dialogs) { /* all injected */ }
Real-world example Because every dependency is an injected interface, the orders view model is fully unit-tested with mocks.

Common follow-ups: What types should view models avoid? | What is a test seam?