标签:
1.引用
using Autofac; using Autofac.Integration.Mvc; using Autofac.Integration.WebApi;
2.在Global中的Application_Start方法中添加如下
// Get your HttpConfiguration. var config = GlobalConfiguration.Configuration; var builder = new ContainerBuilder(); //builder.RegisterType<Helper>().As<IHelper>().InstancePerLifetimeScope(); builder.RegisterControllers(Assembly.GetExecutingAssembly()); builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); // OPTIONAL: Register the Autofac filter provider. builder.RegisterWebApiFilterProvider(config); var container = builder.Build(); config.DependencyResolver = new AutofacWebApiDependencyResolver(container); DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
标签:
原文地址:http://www.cnblogs.com/wuxfly6/p/5504990.html