MVC Autofac 注入点
关键句:
** DependencyResolver.SetResolver(new AutofacDependencyResolver(container));**
protected override void Application_Start(object sender, EventArgs e)
{
#region Autofac注入
var builder = new ContainerBuilder();
builder.RegisterControllers(Assembly.GetExecutingAssembly());
builder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerHttpRequest();
//...
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
#endregion
}