quick start

https://autofaccn.readthedocs.io/en/latest/integration/webapi.html#quick-start

To get Autofac integrated with Web API you need to reference the Web API integration NuGet package, register your controllers, and set the dependency resolver. You can optionally enable other features as well.

protected void Application_Start()
{
var builder = new ContainerBuilder(); // Get your HttpConfiguration.
var config = GlobalConfiguration.Configuration; // Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); // OPTIONAL: Register the Autofac filter provider.
builder.RegisterWebApiFilterProvider(config); // OPTIONAL: Register the Autofac model binder provider.
builder.RegisterWebApiModelBinderProvider(); // Set the dependency resolver to be Autofac.
var container = builder.Build();
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}

The sections below go into further detail about what each of these features do and how to use them.

autofac.webapi2的更多相关文章

  1. .NET领域最为流行的IOC框架之一Autofac WebAPI2使用Autofac实现IOC属性注入完美解决方案 AutoFac容器初步

    .NET领域最为流行的IOC框架之一Autofac   一.前言 Autofac是.NET领域最为流行的IOC框架之一,微软的Orchad开源程序使用的就是Autofac,Nopcommerce开源程 ...

  2. Autofac in webapi2

    安装包:Autofac.webapi2 注意: install-package autofac.webapi2 (注意:您的项目中如果使用的是webapi2,此处必须为webapi2而不是webapi ...

  3. 在MVC5和webAPI下是用Autofac依赖注入

    很多书本中都提到依赖注入,控制反转等概念,这些都是为了实现松耦合层.组件和类目的. 常见的是使用Repository类分离Controller和Model的直接联系.而为了解除Repository类和 ...

  4. OWIN support for the Web API 2 and MVC 5 integrations in Autofac

    Currently, in the both the Web API and MVC frameworks, dependency injection support does not come in ...

  5. webapi框架搭建-依赖注入之autofac

    前言 c#的依赖注入框架有unity.autofac,两个博主都用过,感觉unity比较简单而autofac的功能相对更丰富(自然也更复杂一点),本篇将基于前几篇已经创建好的webapi项目,引入au ...

  6. 使用Autofac动态注入启动Api服务

    Autofac Autofac(https://autofac.org/)是一款.NET的IOC组件,它可以和Owin, Web Api, ASP.NET MVC, .NET Core完美结合,帮助开 ...

  7. mvc webapi+autofac + session 的使用

    先说说我的项目情况:MVC5+AUTOFAC,下面就直接说说怎么加入webapi.autofac的配置.登录使用session 一.MVC5添加WEBAPI 1.添加 参考文章:https://blo ...

  8. C# Autofac集成之Framework WebAPI

    Web API 2集成需要Autofac.WebApi2 NuGet包. Web API集成需要Autofac.WebApi NuGet包. Web API集成为控制器,模型绑定器和操作过滤器提供了依 ...

  9. 记一次autofac+dapper+mvc的框架搭建实践

    1,环境 .net framework4.7.2,Autofac,Autofac.Mvc5,sql server 2,动机 公司项目用的是ef,之前留下代码的大哥,到处using,代码没有分层,连复用 ...

随机推荐

  1. 再谈iOS 7的手势滑动返回功能

    本文转载至 http://blog.csdn.net/jasonblog/article/details/28282147  之前随手写过一篇<使用UIScreenEdgePanGestureR ...

  2. 61、常规控件(4)TabLayout-便捷实现标签

    <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width=&q ...

  3. hdu3625(第一类斯特林数)

    与第二类有些区别! #include <stdio.h> #include <stdlib.h> #include <string.h> #include < ...

  4. AtCoder Tak and Hotels

    题目链接:传送门 题目大意:有 n 个点排成一条直线,每次行动可以移动不超过 L 的距离,每次行动完成必须停在点上, 数据保证有解,有 m 组询问,问从 x 到 y 最少需要几次行动? 题目思路:倍增 ...

  5. @Override must override a superclass method 有关问题解决

    1.Java开发环境时 如果在使用Eclipse开发Java项目时,在使用 @Override 出现以下错误: The method *** of type *** must override a s ...

  6. css3动画效果:2 简易动画

    1. transition动画:鼠标移上去  旋转放大 关键点--  :hover  \ transform: scale(*)  rotate(*deg) cards 2.关键帧动画: 位移动画 t ...

  7. mysql出现) Notice: Trying to get property of non-object in E:\p错误的 原因

    在mysql中,每个命令之间都要留一点空格 如果是这样, $query = "select * from books where " .$searchtype. "lik ...

  8. Android Activity 生成及Activity之间传值

    Activity 是Android中重要的组件,每个Activity对应一个界面,如何生成新的Activity,如何在不同Activity传递数值呢. 一. 生成新的Activity,当然要使用Int ...

  9. Jmeter Aggregate Report 与 Summary Report 分析

    关于Aggregate Report和 Summary Report里面每个字段的说明,在网上有很多资料,在此不做说明. 本文主要讲Aggregate Report与Summary Report对比我 ...

  10. 转!! Eclipse设定和修改文件字符编码格式和换行符

    Window -> Preferences -> General -> Workspace : Text file encoding :Default : 选择此项将设定文件为系统默 ...