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 ...
随机推荐
- java.net.URLConnectioin的http(get,post)请求(原生)
使用Java发送这两种请求的代码大同小异,只是一些参数设置的不同.步骤如下: 通过统一资源定位器(java.net.URL)获取连接器(java.net.URLConnection) 设置请求的参数 ...
- url 字符串中的参数信息
/// <summary> /// 分析 url 字符串中的参数信息 /// </summary> /// <param nam ...
- js-JavaScript高级程序设计学习笔记9
依然第十三章 事件 1.页面上的所有元素都支持鼠标事件,除了mouseenter和mouseleave,所有鼠标事件都会冒泡. 2.修改键:shift.ctrl.alt.meta.四个属性表示修改键的 ...
- ubuntu 通过命令将数据复制到u盘
自己现在也不好意思和别人说自己熟悉linux了,自己用linux,也是当做桌面系统用了,很少熟悉那些linux命令结果上次linux桌面图形界面进不去了只能用命令行,经过几个晚上的折腾终于弄好,现在记 ...
- 【bzoj3611】 大工程
http://www.lydsy.com/JudgeOnline/problem.php?id=3611 (题目链接) 搞了1天= =,感觉人都变蠢了... 题意 给出一个n个节点的树,每条边边权为1 ...
- Visual Studio多版本进行切换的研究
最近在升级公司内部的项目到最新的开发工具Visual Studio 2015,可能在团队开发上会遇到这些问题: 1.团队成员的电脑和系统,设置安装的开发工具参差不齐 2.有些成员的Visual Stu ...
- AutoIt3(AU3)开发的驱动备份工具
项目相关地址 源码:https://github.com/easonjim/Backup_Driver bug提交:https://github.com/easonjim/Backup_Driver/ ...
- alias重启终端失效的问题
如果使用命令 alias xx='xxxx' 那么登出以后,别名就会失效.下次登入的时候就不能用了. 为了保持别名可以把它写入.bashrc 在.bashrc的最后写入想要的别名,比如 alias z ...
- 数据结构2 静态区间第K大/第K小
给定数组$A[1...N]$, 区间$[L,R]$中第$K$大/小的数的指将$A[L...R]$中的数从大到小/从小到大排序后的第$K$个. "静态"指的是不带修改. 这个问题有多 ...
- Markdown的使用简介
以前有摘抄过,然而onenote速度感人,现在又主要用Linux,所以在这里备份一下,好方便用 Linux下推荐remakeble软件,或者直接sublime text,再或者vim,反正我不会ema ...