Navigating between views in WPF / MVVM using dependency injection
A previous post described how to navigate between views in a WPF / MVVM project using the Mediator pattern as a means of passing data around and/or identifying the screen you wish to navigate to. I believe dependency injection is a cleaner and more SOLID-principled way of accomplishing the process of injecting dependencies into the objects of classes that depend on them. In using this, we lessen the need to create objects inside classes and make unit testing easier. The following example shows how to accomplish this as a Visual Studio 2022 WPF project. Step 1. Create a new WPF project Step 2. Install NuGet packages Install the packages necessary to enable dependency injection. In this example we use the ones from Microsoft Extensions, installing them via the Package Manager Console. You will need to install these two: https://www.nuget.org/packages/Microsoft.Extensions.DependencyInjection/ https://www.nuget.org/packages/Microsoft.Extensions.Hosting Copy ...