There is an example project showing Web API in conjunction with OWIN self hosting

https://github.com/autofac/Examples/tree/master/src/WebApiExample.OwinSelfHost

https://github.com/autofac/Examples/blob/master/src/WebApiExample.OwinSelfHost/Startup.cs

Owin

https://autofaccn.readthedocs.io/en/latest/integration/owin.html

OWIN (Open Web Interface for .NET) is a simpler model for composing web-based applications without tying the application to the web server. To do this, a concept of “middleware” is used to create a pipeline through which requests travel.

Due to the differences in the way OWIN handles the application pipeline (detecting when a request starts/ends, etc.) integrating Autofac into an OWIN application is slightly different than the way it gets integrated into more “standard” ASP.NET apps. You can read about OWIN and how it works on this overview.

The important thing to remember is that order of OWIN middleware registration matters. Middleware gets processed in order of registration, like a chain, so you need to register foundational things (like Autofac middleware) first.

Quick Start

To take advantage of Autofac in your OWIN pipeline:

  • Reference the Autofac.Owin package from NuGet.
  • Build your Autofac container.
  • Register the Autofac middleware with OWIN and pass it the container.

Web api integration with owin

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

If you are using Web API as part of an OWIN application, you need to:

  • Do all the stuff for standard Web API integration - register controllers, set the dependency resolver, etc.
  • Set up your app with the base Autofac OWIN integration.
  • Add a reference to the Autofac.WebApi2.Owin NuGet package.
  • In your application startup class, register the Autofac Web API middleware after registering the base Autofac middleware.

A common error in OWIN integration is use of the GlobalConfiguration.Configuration.

In OWIN you create the configuration from scratch.

You should not reference GlobalConfiguration.Configuration anywhere when using the OWIN integration.

integration asp.net web api with autofac and owin的更多相关文章

  1. (转)【ASP.NET Web API】Authentication with OWIN

    概述 本文说明了如何使用 OWIN 来实现 ASP.NET Web API 的验证功能,以及在客户端与服务器的交互过程中,避免重复提交用户名和密码的机制. 客户端可以分为两类: JavaScript: ...

  2. 在ASP.NET Web API 2中使用Owin OAuth 刷新令牌(示例代码)

    在上篇文章介绍了Web Api中使用令牌进行授权的后端实现方法,基于WebApi2和OWIN OAuth实现了获取access token,使用token访问需授权的资源信息.本文将介绍在Web Ap ...

  3. 在ASP.NET Web API 2中使用Owin基于Token令牌的身份验证

    基于令牌的身份验证 基于令牌的身份验证主要区别于以前常用的常用的基于cookie的身份验证,基于cookie的身份验证在B/S架构中使用比较多,但是在Web Api中因其特殊性,基于cookie的身份 ...

  4. ASP.NET Web API 安全筛选器

    原文:https://msdn.microsoft.com/zh-cn/magazine/dn781361.aspx 身份验证和授权是应用程序安全的基础.身份验证通过验证提供的凭据来确定用户身份,而授 ...

  5. ASP.NET Web API安全认证

    http://www.cnblogs.com/codeon/p/6123863.html http://open.taobao.com/docs/doc.htm?spm=a219a.7629140.0 ...

  6. [转] JSON Web Token in ASP.NET Web API 2 using Owin

    本文转自:http://bitoftech.net/2014/10/27/json-web-token-asp-net-web-api-2-jwt-owin-authorization-server/ ...

  7. JSON Web Token in ASP.NET Web API 2 using Owin

    In the previous post Decouple OWIN Authorization Server from Resource Server we saw how we can separ ...

  8. Autofac ASP.NET Web API (Beta) Integration

    With the beta release of ASP.NET MVC 4 and the ASP.NET Web API being released a few weeks ago, I dec ...

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

    在ASP.NET Web API里使用Autofac 1.通过NuGet安装Autofac.WebApi(当时安装的是Autofac 3.1.0) PM > Install-Package Au ...

随机推荐

  1. Codeforces Round #427 (Div. 2)—A,B,C,D题

    A. Key races 题目链接:http://codeforces.com/contest/835/problem/A 题目意思:两个比赛打字,每个人有两个参数v和t,v秒表示他打每个字需要多久时 ...

  2. hdu2094—看似拓扑实际上是一道思维题

    HDU2094  产生冠军 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2094 题意:中文题,就不解释了.题意已经非常清楚了. 这道题的看起来像是一 ...

  3. content: "\e600"

    w图标生成原理. <style> @font-face { font-family: iconfont-sm; src: url(//at.alicdn.com/t/font_143340 ...

  4. Apache Kafka源码分析 – Log Management

    LogManager LogManager会管理broker上所有的logs(在一个log目录下),一个topic的一个partition对应于一个log(一个log子目录)首先loadLogs会加载 ...

  5. python学习笔记(二)— 字典(Dictionary)

    字典是另一种可变容器模型,且可存储任意类型对象.字典是无序的,因为它没有下标,用key来当索引,所以是无序的. 字典的每个键值(key=>value)对用冒号(:)分割,每个对之间用逗号(,)分 ...

  6. Python程序员的10个常见错误(转)

    add by zhj:虽然学Python也有两年了,但这些问题的确容易犯,看来对Python的理解还有些地方不深入.先转了,有时间再好好看 译文:http://blog.jobbole.com/682 ...

  7. SKBUFFER详解

    纯属转载,不敢侵犯别人产权!! 一. SKB_BUFF的基本概念1. 一个完整的skb buff组成(1) struct sk_buff--用于维护socket buffer状态和描述信息(2) he ...

  8. Mysql2索引

    索引分类: 作用:优化查询,select查询有三种情况:缓存查询(不在mysql中进行数据查询),全表查询,索引扫描 Btree(btree b+tree b*tree) Rtree HASH Ful ...

  9. 《Python核心编程》第五章:数字

    PS:[笔记+代码+图片]在GitHub上持续更新,欢迎star:https://github.com/gdouchufu/Core-Python-Programming 本章大纲 介绍Python支 ...

  10. hibernate 单向 n-n

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qilixiang012/article/details/27956057 域模型: 关系数据模型 n ...