The bootstrapper is responsible for initializing Autofac. It will be called at the startup of the application and run once. Let's create the bootstrapper, as shown in the following steps:
- In the root of the News project, create a new file called Bootstrapper.cs.
- Enter the following code:
using Autofac;
using News.ViewModels;
namespace News
{
public static class Bootstrapper
{
public static void Initialize()
{
var containerBuilder = new ContainerBuilder();
containerBuilder.RegisterAssemblyTypes(typeof(App).Assembly)
.Where(x => x.IsSubclassOf(typeof(ViewModel)));
var container = containerBuilder.Build();
Resolver.Initialize(container);
}
}
}
Autofac uses the ContainerBuilder class to configure and finally build the container that we will pass to our resolver. Think of a builder as something that collects a lot of information on what needs...