Since the HeadlinesViewModel depends on the NewsService, we need to register it into our inversion of control (IoC) container. Follow these steps to do so:
- In the News project, open the Bootstrapper.cs file.
- Locate the Initialize() method, add the following line marked in bold, and resolve using references:
public static void Initialize()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterType<NewsService>();
containerBuilder.RegisterType<MainShell>();
containerBuilder.RegisterAssemblyTypes(typeof(App).Assembly).Where(x => x.IsSubclassOf(typeof(ViewModel)));
var container = containerBuilder.Build();
Resolver.Initialize(container);
}
This will allow for the dependency injection of the NewsService.