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. C#日期处理(转) 太忘记了,备忘

    //今天 DateTime.Now.Date.ToShortDateString(); //昨天,就是今天的日期减一 DateTime.Now.AddDays(-1).ToShortDateStrin ...

  2. 剑指Offer——表示数值的字符串

    题目描述: 请实现一个函数用来判断字符串是否表示数值(包括整数和小数).例如,字符串"+100","5e2","-123","3. ...

  3. Kafka简介及使用

    一.Kafka概述 离线部分: Hadoop->离线计算(hdfs / mapreduce) yarn zookeeper->分布式协调(动物管理员) hive->数据仓库(离线计算 ...

  4. 【opencv安裝】opencv2和opencv3共存——安装opencv2和opencv3到指定目录

    安装 opencv2和opencv3共存会导致运行时问题,须分开 下载源码 cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/hom ...

  5. scrollend,滚动结束执行一次

    var timer;window.onscroll = function () { clearTimeout(timer); timer = setTimeout(function () { aler ...

  6. Git 使用配置

    应用情景:使用Git前需要配置 user.name 和 user.email 信息.Git利用这些信息记录谁进行了什么样的操作.Git属于分布式版本管理系统,开发者很多,配置这个就相当于自报家门,告诉 ...

  7. KVm中EPT逆向映射机制分析

    2017-05-30 前几天简要分析了linux remap机制,虽然还有些许瑕疵,但总算大致分析的比较清楚.今天分析下EPT下的逆向映射机制.EPT具体的工作流程可参考前面博文,本文对于EPT以及其 ...

  8. (2.6)Mysql之SQL基础——存储引擎的查看与修改

    (2.6)Mysql之SQL基础——存储引擎的查看与修改 可以使用 show engines; 查看数据库支持的所有的存储引擎: 目录: 1.数据库级别存储引擎 1.1查看现在默认的存储引擎 1.2 ...

  9. Linux系统性能调优之性能分析

    1.Linux性能分析的目的1)找出系统性能瓶颈(包括硬件瓶颈和软件瓶颈):2)提供性能优化的方案(升级硬件?改进系统系统结构?):3)达到合理的硬件和软件配置:4)使系统资源使用达到最大的平衡.(一 ...

  10. 【转载】ARM MMU详解

    一.MMU的产生       许多年以前,当人们还在使用DOS或是更古老的操作系统的时候,计算机的内存还非常小,一般都是以K为单位进行计算,相应的,当时的程序规模也不大,所以内存容量虽然小,但还是可以 ...