使用Autofac在ASP.NET Web API上实现依赖注入
2020-12-13 14:01
标签:cWeb style blog http io color ar 使用 sp 在ASP.NET Web API里使用Autofac 1.通过NuGet安装Autofac.WebApi(当时安装的是Autofac 3.1.0) PM > Install-Package Autofac.WebApi 2.在App_Start文件夹下新建AutofacWebApiConfig类 3.在Global中添加以下代码 使用Autofac在ASP.NET Web API上实现依赖注入 标签:cWeb style blog http io color ar 使用 sp 原文地址:http://www.cnblogs.com/yxlblogs/p/4057485.html public class AutofacWebApiConfig
{
public static void Run()
{
SetAutofacWebApi();
}
private static void SetAutofacWebApi()
{
ContainerBuilder builder = new ContainerBuilder();
HttpConfiguration config = GlobalConfiguration.Configuration;
// Register API controllers using assembly scanning.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterType
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//Call Autofac DI configurations
AutofacWebApiConfig.Run();
}
文章标题:使用Autofac在ASP.NET Web API上实现依赖注入
文章链接:http://soscw.com/essay/33631.html