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分析的更多相关文章

  1. Autofac.Integration.Mvc分析

    Autofac.Integration.Mvc static ILifetimeScope LifetimeScope { get { return (ILifetimeScope)HttpConte ...

  2. Autofac.Integration.Mvc.Owin分析

    using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Secur ...

  3. Autofac.Integration.Owin

    public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeScope container) { if ...

  4. openwrt luci web分析

    openwrt luci web分析 来源 https://www.jianshu.com/p/596485f95cf2 www/cbi-bin/luci #!/usr/bin/lua --cgi的执 ...

  5. 读了这篇文章,你将变身web分析大师

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 本文由shirishiyue发表于云+社区专栏 1.工具介绍 ​ 这是一个非常详细且专业的web页面性能分析工具,而且开源的!如果你打不开其 ...

  6. 使用Autofac,提示重写成员“Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(System.Type)”时违反了继承安全性规则。重写方法的安全可访问性必须与所重写方法的安全可访问性匹配。

    接触Autofac大概有2天左右,第2天,亲自动手搭建demo,搭完,以为大功告成的时候,提示了这个错误,网上找了很多方法,都没有解决. 为以后的朋友,避免踩坑,分享一下我的解决方法. Dmeo我是新 ...

  7. 未能加载文件或程序集“Autofac.Integration.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da”或它的某一个依赖项。找到的程序集清单定义与程序集引用不匹配。 (异常来自 HRESULT:0x80131040)

    是因为web.config中dependentAssembly结点下的版本号和当前引用的程序集的版本号不一致!

  8. [一道蓝鲸安全打卡Web分析] 文件上传引发的二次注入

    蓝鲸打卡的一个 web 文件上传引发二次注入的题解和思考 蓝鲸文件管理系统 源代码地址:http://www.whaledu.com/course/290/task/2848/show 首先在设置文件 ...

  9. Web分析日志分析2

    http://www.docin.com/p-649515490.html http://wenku.baidu.com/link?url=kB-83fbl1Zc3Y6U2BYLj-lKMWShe8Z ...

随机推荐

  1. mysql基础语法及拓展到web中的sql注入

    本来是想写下javaweb的mvc(tomcat, spring, mysql)的搭建,  昨天搭到凌晨3点, 谁知道jdbcTemplate的jar包不好使, 想死的心都有了, 想想还是休息一下, ...

  2. oracle触发器调用java程序

    1.创建java程序:接收存储过程传递的参数,发送socket通信. create or replace and compilejava source named jym as import java ...

  3. 使用HttpSessionListener接口监听Session的创建和失效

    转自:http://uule.iteye.com/blog/824115 HttpSessionListener : Session创建事件发生在每次一个新的session创建的时候,类似地Sessi ...

  4. 【BZOJ-3709】Bohater 贪心

    3709: [PA2014]Bohater Time Limit: 5 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 835  Solved:  ...

  5. java integer对象判断两个数字是否相等

    java integer对象判断两个数字是否相等,不一定对 问题发生的背景:javaweb的项目,起先,因为在java中实体类中的int类型在对象初始化之后会给int类型的数据默认赋值为0,这样在很多 ...

  6. Nodejs系列-01-开篇

    1.解决什么问题 1. 并发连接 举个例子,想象一个场景,我们在银行排队办理业务,我们看看下面两个模型. (1)系统线程模型: 这种模型的问题显而易见,服务端只有一个线程,并发请求(用户)到达只能处理 ...

  7. POI2007_zap 莫比乌斯反演

    题意:http://hzwer.com/4205.html 同hdu1695 #include <iostream> #include <cstring> #include & ...

  8. [NOIP2014] 提高组 洛谷P2296 寻找道路

    题目描述 在有向图G 中,每条边的长度均为1 ,现给定起点和终点,请你在图中找一条从起点到终点的路径,该路径满足以下条件: 1 .路径上的所有点的出边所指向的点都直接或间接与终点连通. 2 .在满足条 ...

  9. easyui使用datagrid时列名包含特殊字符导致表头与数据错位的问题

    做一个用easyui的datagrid显示数据的功能时发现表格的列头与数据错位了,而且这个现象不总是能重现,一直没搞清楚原因.后来偶然在控制台看出了一点端倪: 推测表头或者单元格的class名应该是用 ...

  10. C#12种顺序排序

    这篇主要写关于顺序排序的十二种算法,也是我有关算法的第一帖.主要是写,对每种算法的理解与测试. 速度测试,主要根据一千.一万.五万.百万这 四种.速度纪录还是用Stopwatch 这个类.使用随机数R ...