欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

使用AutoFac在ASP.NET Web API上实现依赖注入

程序员文章站 2022-03-26 23:01:53
在ASP.NET Web API里使用Autofac 通过NuGet安装Autofac.WebApi。(Nuget会安装依赖的Autofac.dll)。 PM > Install-Package Autofac.WebApi 引用如下命名空间: using Autofac; using Autofa ......

     在ASP.NET Web API里使用Autofac

     通过NuGet安装Autofac.WebApi。(Nuget会安装依赖的Autofac.dll)。

     PM > Install-Package Autofac.WebApi

     引用如下命名空间:

     using Autofac;
     using Autofac.Integration.WebApi;

     代码配置Autofac 可参看http://efmvc.codeplex.com/ :一个样例Web程序,用来展示ASP.NET MVC、EF Code First以及架构实践。

     相关资源:Dependency Injection with ASP.NET Web API and Autofac

                     http://www.codemonkeez.com/2013/04/aspnet-web-api-autofac-self-hosting.html