Autofac.Integration.Web分析
using System;
using System.Web;
using Autofac.Core.Lifetime; namespace Autofac.Integration.Web
{
/// <summary>
/// Provides application-wide and per-request containers.
/// </summary>
public class ContainerProvider : IContainerProvider
{
readonly IContainer _applicationContainer;
readonly Action<ContainerBuilder> _requestLifetimeConfiguration; /// <summary>
/// Initializes a new instance of the <see cref="ContainerProvider"/> class.
/// </summary>
/// <param name="applicationContainer">The application container.</param>
public ContainerProvider(IContainer applicationContainer)
{
if (applicationContainer == null) throw new ArgumentNullException("applicationContainer");
_applicationContainer = applicationContainer;
} /// <summary>
/// Initializes a new instance of the <see cref="ContainerProvider"/> class.
/// </summary>
/// <param name="applicationContainer">The application container.</param>
/// <param name="requestLifetimeConfiguration">An action that will be executed when building
/// the per-request lifetime. The components visible within the request can be
/// customised here.</param>
public ContainerProvider(IContainer applicationContainer, Action<ContainerBuilder> requestLifetimeConfiguration)
: this(applicationContainer)
{
if (requestLifetimeConfiguration == null) throw new ArgumentNullException("requestLifetimeConfiguration");
_requestLifetimeConfiguration = requestLifetimeConfiguration;
} /// <summary>
/// Dispose of the current request's container, if it has been
/// instantiated.
/// </summary>
public void EndRequestLifetime()
{
var rc = AmbientRequestLifetime;
if (rc != null)
rc.Dispose();
} /// <summary>
/// The global, application-wide container.
/// </summary>
/// <value></value>
public ILifetimeScope ApplicationContainer
{
get
{
return _applicationContainer;
}
} /// <summary>
/// The container used to manage components for processing the
/// current request.
/// </summary>
/// <value></value>
public ILifetimeScope RequestLifetime
{
get
{
var result = AmbientRequestLifetime;
if (result == null)
{
result = _requestLifetimeConfiguration == null ?
ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag) :
ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag, _requestLifetimeConfiguration); AmbientRequestLifetime = result;
} return result;
}
} static ILifetimeScope AmbientRequestLifetime
{
get
{
return (ILifetimeScope)HttpContext.Current.Items[typeof(ILifetimeScope)];
}
set
{
HttpContext.Current.Items[typeof(ILifetimeScope)] = value;
}
}
}
}
/// <summary>
/// The container used to manage components for processing the
/// current request.
/// </summary>
/// <value></value>
public ILifetimeScope RequestLifetime
{
get
{
var result = AmbientRequestLifetime;
if (result == null)
{
result = _requestLifetimeConfiguration == null ?
ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag) :
ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag, _requestLifetimeConfiguration); AmbientRequestLifetime = result;
} return result;
}
} static ILifetimeScope AmbientRequestLifetime
{
get
{
return (ILifetimeScope)HttpContext.Current.Items[typeof(ILifetimeScope)];
}
set
{
HttpContext.Current.Items[typeof(ILifetimeScope)] = value;
}
}
Autofac.Integration.Web分析的更多相关文章
- Autofac.Integration.Mvc分析
Autofac.Integration.Mvc static ILifetimeScope LifetimeScope { get { return (ILifetimeScope)HttpConte ...
- Autofac.Integration.Mvc.Owin分析
using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Secur ...
- Autofac.Integration.Owin
public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeScope container) { if ...
- openwrt luci web分析
openwrt luci web分析 来源 https://www.jianshu.com/p/596485f95cf2 www/cbi-bin/luci #!/usr/bin/lua --cgi的执 ...
- 读了这篇文章,你将变身web分析大师
欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由shirishiyue发表于云+社区专栏 1.工具介绍 这是一个非常详细且专业的web页面性能分析工具,而且开源的!如果你打不开其 ...
- 使用Autofac,提示重写成员“Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(System.Type)”时违反了继承安全性规则。重写方法的安全可访问性必须与所重写方法的安全可访问性匹配。
接触Autofac大概有2天左右,第2天,亲自动手搭建demo,搭完,以为大功告成的时候,提示了这个错误,网上找了很多方法,都没有解决. 为以后的朋友,避免踩坑,分享一下我的解决方法. Dmeo我是新 ...
- 未能加载文件或程序集“Autofac.Integration.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)
是因为web.config中dependentAssembly结点下的版本号和当前引用的程序集的版本号不一致!
- [一道蓝鲸安全打卡Web分析] 文件上传引发的二次注入
蓝鲸打卡的一个 web 文件上传引发二次注入的题解和思考 蓝鲸文件管理系统 源代码地址:http://www.whaledu.com/course/290/task/2848/show 首先在设置文件 ...
- Web分析日志分析2
http://www.docin.com/p-649515490.html http://wenku.baidu.com/link?url=kB-83fbl1Zc3Y6U2BYLj-lKMWShe8Z ...
随机推荐
- C#-WinForm-布局-Anchor-锁定布局、Dock-填充布局、工具箱中的<容器>
Anchor - 锁定布局,锁定控件对于其父控件或窗体的位置,保持与边框固定的距离还是居中等 Dock - 填充布局,控件是否如何进行填充 ============================== ...
- VS2015 安装mvc4安装包以及vs2010 sp1后导致Razor语法失效代码不高亮(能正常运行)/视图页面无法智能提示(.cshtml)解决办法
VS2015默认asp.net mvc 版本为5.0以上,默认不支持创建5.0以下的版本.所以想要使用mvc 4.0只能单独安装.在网上搜了几篇教程后在微软官网下载了Visual Studio 201 ...
- Linux网卡的相关配置总结
当有多个网卡的时候,我们需要进行相关的配置. 一.如何改变网卡的名字? 修改/etc/udev/rules.d/70-persistent-net.rules 进去之后的效果是 根据mac地址,把没用 ...
- OPENGL——背面剔除
Opengl 表面剔除是提高 Opengl 程序渲染效率的一个有效途径. 我们知道,OpenGL 渲染的基本单位是一个个的三角形面片.无论多么复杂的3D 模 型都是由一个个基本的三角型的面片组成的. ...
- Android Studio打包全攻略
转载:http://www.2cto.com/kf/201606/517300.html 初出茅庐 手动打包 怎么手动打包 项目写完了,现在需要把应用上传到市场,问题出现-怎么把代码变成.apk(An ...
- [bzoj1984]月下“毛景树”
Description 毛毛虫经过及时的变形,最终逃过的一劫,离开了菜妈的菜园.毛毛虫经过千山万水,历尽千辛万苦,最后来到了小小的绍兴一中的校园里.爬啊爬~爬啊爬~~毛毛虫爬到了一颗小小的" ...
- 下载Spring的jar包的方法
- Bzoj2118 墨墨的等式
Time Limit: 10 Sec Memory Limit: 259 MBSubmit: 1488 Solved: 578 Description 墨墨突然对等式很感兴趣,他正在研究a1x1+ ...
- 洛谷P2242 公路维修问题(Road)
题目描述 在一个夜黑风高,下着暴风雨的夜晚,farmer John的牛棚的屋顶.门被吹飞了. 好在许多牛正在度假,所以牛棚没有住满. 牛棚一个紧挨着另一个被排成一行,牛就住在里面过夜. 有些牛棚里有牛 ...
- tyvj2018 小猫爬山
之前做过一道题"破锣摇滚乐队",把猫都编了号,每辆车只能装一些编号递增的猫,而且前一辆车的猫编号都比后一辆车小.那道题的DP状态是:f[i][j]表示装了前i只猫,使用了j辆车时第 ...