https://www.asp.net/media/4071077/aspnet-web-api-poster.pdf

1.You can host Web API inside IIS or inside your own process (self-hosting).

2.The HTTP request message is first converted to an HttpRequestMessage object, which provides strongly typed access to the HTTP message.

3.HttpMessageHandler

3.1  Delegating Handler

3.2  HTTPRoutingDispatcher

3.3  HTTPControllerDispatcher

StepA:Create Api Controller

4.Controller

StepB: Select controller action

4.1  Authentication Filters

4.2  Authorization Filters

StepC:Model Binding

4.3  Action Filters  源码https://github.com/aspnet/AspNetWebStack/blob/master/src/System.Web.Http/Filters/ActionFilterAttribute.cs

StepE: Invoke Action -->这里有可能触发Exception Filters

StepD:Result Conversion

在看pdf的时候,还需要注意标准

实际使用中遇到的问题

使用Autofac进行构造函数注入,但是依赖api传递进来的参数。

之前使用的方案是,在ActionFilter中拿到controller以及api参数,然后手动调用resolve去实例化,本来需要构造函数注入的属性。

调整之后:(必须在DelegateHandler中解析,因为ActionFilter的执行,是在Controller实例化之后)

在DelegateHandler中解析参数,并存储。然后在Autofac的lambda注册的地方,委托那边直接OwinRequestScopeContext拿到参数。

var apiRequest = request.Content.ReadAsAsync<ApiRequest<dynamic>>().Result;
OwinRequestScopeContext.Current.Items["CountryCode"] = apiRequest.Header.OpCo;

扩展阅读

https://exceptionnotfound.net/the-asp-net-web-api-2-http-message-lifecycle-in-43-easy-steps-2/

http://rajeevdotnet.blogspot.com/2018/03/the-lifecycle-of-aspnet-web-api.html

http://www.cnblogs.com/shanyou/archive/2012/03/17/2404180.html

ASP.NET WEB API 2: HTTP MESSAGE LIFECYLE的更多相关文章

  1. ASP.NET Web API - 使用 Castle Windsor 依赖注入

    示例代码 项目启动时,创建依赖注入容器 定义一静态容器 IWindsorContainer private static IWindsorContainer _container; 在 Applica ...

  2. 【ASP.NET Web API教程】3.4 HttpClient消息处理器

    原文:[ASP.NET Web API教程]3.4 HttpClient消息处理器 注:本文是[ASP.NET Web API系列教程]的一部分,如果您是第一次看本博客文章,请先看前面的内容. 3.4 ...

  3. Custom Exception in ASP.NET Web API 2 with Custom HttpResponse Message

    A benefit of using ASP.NET Web API is that it can be consumed by any client with the capability of m ...

  4. Lifecycle of an ASP.NET Web API Message

    ASP.NET Web API, as we know now, is a framework that helps build Services over HTTP. Web API was int ...

  5. [整理]ASP.NET WEB API 2学习

    目录 1 快速入门 1.1实例 1.1.1初识WEB API 2 1.1.2 Action Results 的改变 1.1.3 路由的新增特性 1.1.4 消息管道的变化 1.1.4.1 HttpMe ...

  6. ASP.NET Web API与Owin OAuth:使用Access Toke调用受保护的API

    在前一篇博文中,我们使用OAuth的Client Credential Grant授权方式,在服务端通过CNBlogsAuthorizationServerProvider(Authorization ...

  7. 8 种提升 ASP.NET Web API 性能的方法

    ASP.NET Web API 是非常棒的技术.编写 Web API 十分容易,以致于很多开发者没有在应用程序结构设计上花时间来获得很好的执行性能. 在本文中,我将介绍8项提高 ASP.NET Web ...

  8. 推荐升级ASP.NET Web API 2

    ASP.NET Web API 使用很长时间了,期间也碰到不少问题,升级到WebAPI2后这些问题都解决了,稳定性方面也提升不少,所以推荐使用.碰到的问题是下面的2类: 1.multipart/for ...

  9. Self Host模式下的ASP. NET Web API是如何进行请求的监听与处理的?

    构成ASP.NET Web API核心框架的消息处理管道既不关心请求消息来源于何处,也不需要考虑响应消息归于何方.当我们采用Web Host模式将一个ASP.NET应用作为目标Web API的宿主时, ...

随机推荐

  1. 【Android M】预制的 Google GMS包

    目录:android/vendor/google/apps .├── AndroidPay│   ├── Android.mk│   ├── AndroidPay_arm64.apk│   ├── A ...

  2. iconfont阿里爸爸做的开源图库

    iconfont 三种使用姿势 1.unicode格式 优点 兼容性最好,支持ie6+ 支持按字体的方式去动态调整图标大小,颜色等等 缺点 不支持多色图标 在不同的设备浏览器字体的渲染会略有差别,在不 ...

  3. 【BZOJ2007】[Noi2010]海拔 对偶图最短路

    [BZOJ2007][Noi2010]海拔 Description YT市是一个规划良好的城市,城市被东西向和南北向的主干道划分为n×n个区域.简单起见,可以将YT市看作 一个正方形,每一个区域也可看 ...

  4. android 点九工具介绍

    1=============================9.png简介:“点九”是andriod平台的应用软件开发里的一种特殊的图片形式,文件扩展名为:.9.png android平台有多种不同的 ...

  5. 一个Activity中使用两个layout实例

    package com.sbs.aas2l; import android.app.Activity; import android.os.Bundle; import android.view.Vi ...

  6. oracle和mysql如何快速查看每个表的数据量?

    oracle: select t.table_name,t.num_rows from user_tables t ORDER BY NUM_ROWS DESC; mysql: use informa ...

  7. 利用aspose-words 实现 java中word转pdf文件

    利用aspose-words  实现 java中word转pdf文件 首先下载aspose-words-15.8.0-jdk16.jar包 引入jar包,编写Java代码 package test; ...

  8. Code Forces 652D Nested Segments(离散化+树状数组)

     Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  9. spring boot实战(第一篇)第一个案例

    版权声明:本文为博主原创文章,未经博主允许不得转载.   目录(?)[+]   spring boot实战(第一篇)第一个案例 前言 写在前面的话 一直想将spring boot相关内容写成一个系列的 ...

  10. D. Babaei and Birthday Cake---cf629D(LIS线段树优化)

    题目链接:http://codeforces.com/problemset/problem/629/D 题意就是现有n个蛋糕,蛋糕的形状是圆柱体,每个蛋糕的体积就是圆柱体的体积,每个蛋糕的编号是1-- ...