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

 }
posted @ 2016-08-18 16:25 _DN 阅读(...) 评论(...) 编辑 收藏