The resolver will be responsible for creating our objects for us, based on the type that we have in the request. It wraps the specific functionality of Autofac, making it easy to replace Autofac if needed. Let's create the resolver, as follows:
- In the root folder of the News project, create a new file called Resolver.cs.
- Add the following code to the file:
using Autofac;
namespace News
{
public static class Resolver
{
private static IContainer container;
public static void Initialize(IContainer container)
{
Resolver.container = container;
}
public static T Resolve<T>()
{
return container.Resolve<T>();
}
}
}
The container property of the IContainer type is defined in Autofac and represents a container that holds the configuration on how to resolve types. The Initialize method takes an instance of an object that implements the IContainer interface and assigns it to...