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 ...
随机推荐
- css 小三角
span{ display: inline-block; border-top: 100px solid red; border-right: 100px solid transparent; bor ...
- 本篇文章: HTML DOM 对象
HTML DOM 对象 本篇主要介绍HTML DOM 对象:Document.Element.Attr.Event等4个对象. 目录 1. Document 对象:表示文档树的根节点,大部分属性和方法 ...
- Hash_1014: [JSOI2008]火星人prefix
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- Android成长日记-使用PagerAdapter实现页面切换
Tip:此方式可以实现页面切换 1. 创建view1.xml,view2.xml,view3.xml,main.xml 在main.xml中创建 <android.support.v4.view ...
- nginx ssl证书安装配置
原理图: - 客户端生成一个随机数 random-client,传到服务器端(Say Hello) - 服务器端生成一个随机数 random-server,和着公钥,一起回馈给客户端(I got it ...
- css优化
>>.li设置了display:inline-block,会有空隙,可在父元素ul下设置font-size:0 >>.ie下不支持margin:0 auto; >> ...
- 对oracle数据库进行增删改更新操作,executeUpdate()执行卡住了
原因是:oracle数据库更新数据后需要commit,不然会堵塞,就会卡住 那么每次调用executeUpdate()完后,数据库要自动commit才可以. 我的基类加了一下,注意红色字体部分代码: ...
- NXP Mifare S50标准IC卡- 访问位(Access Bits) 分析
Mifare S50 标准IC卡有1K 字节的EEPROM,主要用来存储数据和控制信息.1K 字节的EEPROM分成16 个区,每区又分成4 段,每1段中有16 个字节.每个区的最后一个段叫“尾部&q ...
- 如何排查APP服务端和客户端是否支持ATS
服务端排查 取得客户端直接连接的服务端域名及端口,例如mob.com.cn,端口443,即HTTPS默认端口.针对公网可访问的生产环境地址,建议使用的在线监测工具.https://wosign.ssl ...
- SVM支持向量机的高维映射与核函数-记录毕业论文2
上一篇博客将了在数据集线性可分的情况下的支持向量机,这篇主要记录如何通过映射到高维解决线性不可分的数据集和如何通过核函数减少内积计算量的理论思想. [5]径向基函数的核函数:https://www.q ...