Now, we need to create a helper class for Inversion of Control (IoC). This will help us create types based on a configured IoC container. In this project, we will use Autofac as the IoC library. Let's set this up:
- Install the Autofac NuGet package in the Weather project.
- Create a new class called Resolver in the Weather project.
- Add a private static field called container of the IContainer type (from Autofac).
- Add a public static method called Initialize with IContainer as a parameter. Set the value of the parameter to the container field.
- Add a generic public static method called Resolve<T>, which will return an instance of an object of the type specified with the T parameter. The Resolve<T> method will then call the Resolve<T> method on the IContainer instance that was passed to it during initialization.
- The code should now look as follows:
using Autofac;
namespace Weather
{...