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 ...
随机推荐
- 100726C
显而易见,我们要找子串,每次记录前缀和,算出余数,然后通过一个数组保存余数,答案就是加上之前余数的总和,要注意整除的情况 #include<iostream> #include<cs ...
- java的执行与加载的过程
第一.我们编写一个.java源文件: 第二.通过编译器javac.exe把.java源文件编译为.class字节码文件并装入类装载器里: 第三.java虚拟机java.exe把字节码文件解释为各个平台 ...
- Lucene学习笔记
师兄推荐我学习Lucene这门技术,用了两天时间,大概整理了一下相关知识点. 一.什么是Lucene Lucene即全文检索.全文检索是计算机程序通过扫描文章中的每一个词,对每一个词建立一个索引,指明 ...
- Pycharm设置
File->settings->Editor->File and Code Templates->Python Script #!/usr/bin/env python # e ...
- Matlab中cell存储为txt
clc clear all [data1,data3]=textread('E:\RSWeb\mahoyt数据集\movielens\u.user','%s%*d%s%*s%*s','delimite ...
- Deformity ASP/ASPX Webshell、Webshell Hidden Learning
catalog . Active Server Page(ASP) . ASP.NET . ASP WEBSHELL变形方式 . ASPX WEBSHELL变形方式 . webshell中常见的编码转 ...
- Spring mvc web 配置
Spring Framework本身没有Web功能, Spring MVC使用WebApplicationContext类扩展ApplicationContext ,使得拥有web功能.那么,Spri ...
- Scala implicit
Scala implicit implicit基本含义 在Scala中有一个关键字是implicit, 之前一直不知道这个货是干什么的,今天整理了一下. 我们先来看一个例子: def display( ...
- 使用enum建立简单的状态机
Overview The enum in Java is more powerful than many other languages which can lead to surprising us ...
- linux安装Mac的默认Monaco字体
Monaco字体是我最喜欢的编程字体,如果你想在linux上面安装,只需要在terminal中执行: curl -kL https://raw.github.com/cstrap/monaco-fon ...