autofac解析Mvc和Webapi的坑
我们在项目中很早就开始使用autofac,也以为知道与mvc和webapi集成的做法。 var builder = new ContainerBuilder(); // Mvc Register builder.RegisterControllers(Assembly.GetExecutingAssembly()).AsSelf().PropertiesAutowired(); builder.RegisterFilterProvider(); builder.RegisterType<UserService>().As<IUserService>().InstancePerLifetimeScope(); //WebApi Register builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).AsSelf().PropertiesAutowired(); builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration); builder.RegisterWebApiModelBinderProvider(); var container = builder.Build(); // Set the dependency