We need to create a helper class that will ease the process of resolving object graphs through Autofac. This will help us create types based on a configured IoC container.
In this project, we will use Autofac as the IoC library:
- Install the Autofac NuGet package in the Chat project.
- Create a new class called Resolver in the Chat 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 static public method called Resolve, which will return an instance that is based on the argument type, with the Resolve method of IContainer:
using Autofac;
public class Resolver
{
private static IContainer container;
public static void Initialize(IContainer container)
{
Resolver...