Web API 源码剖析之默认配置(HttpConfiguration)
Web API 源码剖析之默认配置(HttpConfiguration)
我们在上一节讲述了全局配置和初始化。本节我们将就全局配置的Configuration只读属性进行展开,她是一个类型为HttpConfiguration。 它在Web Api 主要为整个API 做一些最基础的工作,比如定义默认
- 路由表(Routes)
- 过滤器(Filters)
- 默认消息处理程序(MessageHandlers)
- 属性字典(Properties)
- 依赖注入解耦器(DependencyResolver)
- 错误处理策略(IncludeErrorDetailPolicy)
- 服务(Services,这里的服务是之为Web ApI 框架的服务对应的接口和实现)
- 媒体格式程序(Formatters)
- 参数绑定规则(ParameterBindingRules)。
以上 就是配置的属性。 接下来将就部分属性展开。
Formatters
默认格式化程序,是一个MediaTypeFormatterCollection类型。
API 里定义4个默认格式:
- JsonMediaTypeFormatter:对应的是用来处理请求头是application/json或text/json格式,
- XmlMediaTypeFormatter:对应的是用来处理请求头是application/xml格式
- FormUrlEncodedMediaTypeFormatter:对应的是用来处理请求头是application/x-www-form-urlencoded,
- JQueryMvcFormUrlEncodedFormatter
Services
默认服务定义如下:
public DefaultServices(HttpConfiguration configuration)
{
if (configuration == null)
{
throw Error.ArgumentNull("configuration");
}_configuration = configuration;
// Initialize the dictionary with all known service types, even if the list for that service type is
// empty, because we will throw if the developer tries to read or write unsupported types.SetSingle<IActionValueBinder>(new DefaultActionValueBinder());
SetSingle<IApiExplorer>(new ApiExplorer(configuration));
SetSingle<IAssembliesResolver>(new DefaultAssembliesResolver());
SetSingle<IBodyModelValidator>(new DefaultBodyModelValidator());
SetSingle<IContentNegotiator>(new DefaultContentNegotiator());
SetSingle<IDocumentationProvider>(null); // MissingSetMultiple<IFilterProvider>(new ConfigurationFilterProvider(),
new ActionDescriptorFilterProvider());SetSingle<IHostBufferPolicySelector>(null);
SetSingle<IHttpActionInvoker>(new ApiControllerActionInvoker());
SetSingle<IHttpActionSelector>(new ApiControllerActionSelector());
SetSingle<IHttpControllerActivator>(new DefaultHttpControllerActivator());
SetSingle<IHttpControllerSelector>(new DefaultHttpControllerSelector(configuration));
SetSingle<IHttpControllerTypeResolver>(new DefaultHttpControllerTypeResolver());
SetSingle<ITraceManager>(new TraceManager());
SetSingle<ITraceWriter>(null);// This is a priority list. So put the most common binders at the top.
SetMultiple<ModelBinderProvider>(new TypeConverterModelBinderProvider(),
new TypeMatchModelBinderProvider(),
new KeyValuePairModelBinderProvider(),
new ComplexModelDtoModelBinderProvider(),
new ArrayModelBinderProvider(),
new DictionaryModelBinderProvider(),
new CollectionModelBinderProvider(),
new MutableObjectModelBinderProvider());
SetSingle<ModelMetadataProvider>(new DataAnnotationsModelMetadataProvider());
SetMultiple<ModelValidatorProvider>(new DataAnnotationsModelValidatorProvider(),
new DataMemberModelValidatorProvider());// This is an ordered list,so put the most common providers at the top.
SetMultiple<ValueProviderFactory>(new QueryStringValueProviderFactory(),
new RouteDataValueProviderFactory());ModelValidatorCache validatorCache = new ModelValidatorCache(new Lazy<IEnumerable<ModelValidatorProvider>>(() => this.GetModelValidatorProviders()));
SetSingle<IModelValidatorCache>(validatorCache);SetSingle<IExceptionHandler>(new DefaultExceptionHandler());
SetMultiple<IExceptionLogger>();_serviceTypesSingle = new HashSet<Type>(_defaultServicesSingle.Keys);
_serviceTypesMulti = new HashSet<Type>(_defaultServicesMulti.Keys);// Reset the caches and the known dependency scope
ResetCache();
}
默认的Action绑定规则:ParameterBindingRules
ParameterBindingRules = DefaultActionValueBinder.GetDefaultParameterBinders();
有兴趣的朋友可以下载web Api 源码查看。http://aspnetwebstack.codeplex.com/wikipage?title=Contributors.
Web API 源码剖析之默认配置(HttpConfiguration)的更多相关文章
- Web API 源码剖析之默认消息处理程序链之路由分发器(HttpRoutingDispatcher)
Web API 源码剖析之默认消息处理程序链-->路由分发器(HttpRoutingDispatcher) 我们在上一节讲述了默认的DefaultServer(是一个类型为HttpServer的 ...
- Web API 源码剖析之全局配置
Web API 源码剖析之全局配置 Web API 均指Asp.net Web API .本节讲述的是基于Web API 系统在寄宿于IIS. 本节主要讲述Web API全局配置.它是如何优雅的实现 ...
- Web API 源码剖析之默认消息处理程序链--》路由分发器(HttpRoutingDispatcher)
我们在上一节讲述了默认的DefaultServer(是一个类型为HttpServer的只读属性,详情请参考 Web API 源码剖析之全局配置).本节将讲述DefaultHandler(是一个Http ...
- Web API源码剖析之HttpServer
Web API源码剖析之HttpServer 上一节我们讲述全局配置.本节将讲述全局配置的DefaultServer,它是一个HttpServer类型. 主要作用就是接受每一次请求,然后分发给消息处理 ...
- Web Api源码(路由注册)
这篇文章只是我学习Web API框架的输出,学习方法还是输出倒逼输入比较行得通,所以不管写的好不好,坚持下去,肯定有收获.篇幅比较长,仔细思考阅读下来大约需要几分钟. 做.NET开发有好几年时间了,从 ...
- STL源码剖析之空间配置器
本文大致对STL中的空间配置器进行一个简单的讲解,由于只是一篇博客类型的文章,无法将源码表现到面面俱到,所以真正感兴趣的码农们可以从源码中或者<STL源码剖析>仔细了解一下. 1,为什么S ...
- 《STL源码剖析》环境配置
首先,去侯捷网站下载相关文档:http://jjhou.boolan.com/jjwbooks-tass.htm. 这本书采用的是Cygnus C++ 2.91 for windows.下载地址:ht ...
- 长期作业:web框架源码剖析
Tornado框架 1.1. 手动安装 1.2. 从简单的开始:分析红框部分的源码 Django框架
- WorldWind源码剖析系列:配置载入器类ConfigurationLoader
配置载入器类ConfigurationLoader主要从指定的路径中加载保存星球相关参数的xml文件,从中读取数据来构造星球对象及其所关联的可渲染子对象列表并返回.该类的类图如下所示. 该类所包含的主 ...
随机推荐
- Vue.js更改调试地址端口号
Vue项目一般使用自带的脚手架工具vue-cli和webpack打包方式进行项目构建运行.开发中,我们在控制台输入命令行npm run dev部署项目后,默认开启的页面调试地址是8080端口.但是有时 ...
- PHP发明人谈MVC和网站设计架构
PHP是全世界上使用率最高的网页开发语言,台湾每4个网站,就有1个用PHP语言开发.1995年发明PHP语言的Rasmus Lerdorf,也是打造出Yahoo全球服务网站的架构师之一,他首度来台分享 ...
- Texas Instruments matrix-gui-2.0 hacking -- menubar.php
<?php /* * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/ * * * Redistrib ...
- [Algorithm] A nonrecursive algorithm for enumerating all permutations of the numbers {1,2,...,n}
def permutationN(n): a=[None]*n for i in range(n): a[i]=i+1 sum=1 for j in range(n): sum*=(j+1) i=0 ...
- Ordering Tasks 拓扑排序
John has n tasks to do. Unfortunately, the tasks are not independent and the execution of one task i ...
- 【java规则引擎】《Drools7.0.0.Final规则引擎教程》第4章 4.2 lock-on-active
转载至:https://blog.csdn.net/wo541075754/article/details/75208955 lock-on-active 当在规则上使用ruleflow-group属 ...
- ZH奶酪:隐马尔可夫模型学习小记——forward算法+viterbi算法+forward-backward算法(Baum-welch算法)
网上关于HMM的学习资料.博客有很多,基本都是左边摘抄一点,右边摘抄一点,这里一个图,那里一个图,公式中有的变量说不清道不明,学起来很费劲. 经过浏览几篇博文(其实有的地方写的也比较乱),在7张4开的 ...
- JMeter分布式部署的大致步骤以及误区解释
master和slave机要在同一网段内,才能做分布式(Jmeter要配环境变量,这样不用手动起server) 分布式不成功,解决方案: 1.master端和slave端要ping通 2.ping通后 ...
- coffeescript学习
test2.coffeestdin = process.openStdin()stdin.setEncoding 'utf8' stdin.on 'data', (input) -> n ...
- Spring 集成开发工具(STS)安装及配置
安装 spring 集成开发工具,下载地址:https://spring.io/tools 下载后,解压,双击 STS ,运行. 如果提示: 去oracle的网站上下载了1.8版本的jdk,下载地址如 ...