Autofac.Integration.Mvc分析
Autofac.Integration.Mvc
static ILifetimeScope LifetimeScope
{
get { return (ILifetimeScope)HttpContext.Current.Items[typeof(ILifetimeScope)]; }
set { HttpContext.Current.Items[typeof(ILifetimeScope)] = value; }
}
namespace Autofac.Integration.Mvc
{
/// <summary>
/// An <see cref="IHttpModule"/> and <see cref="ILifetimeScopeProvider"/> implementation
/// that creates a nested lifetime scope for each HTTP request.
/// </summary>
internal class RequestLifetimeHttpModule : IHttpModule
{
/// <summary>
/// Gets the lifetime scope provider that should be notified when a HTTP request ends.
/// </summary>
internal static ILifetimeScopeProvider LifetimeScopeProvider { get; private set; } /// <summary>
/// Initializes a module and prepares it to handle requests.
/// </summary>
/// <param name="context">An <see cref="T:System.Web.HttpApplication"/> that provides access to the
/// methods, properties, and events common to all application objects within an ASP.NET application</param>
/// <exception cref="System.ArgumentNullException">
/// Thrown if <paramref name="context" /> is <see langword="null" />.
/// </exception>
public void Init(HttpApplication context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
context.EndRequest += OnEndRequest;
} /// <summary>
/// Disposes of the resources (other than memory) used by the module that implements <see cref="T:System.Web.IHttpModule"/>.
/// </summary>
public void Dispose()
{
} public static void SetLifetimeScopeProvider(ILifetimeScopeProvider lifetimeScopeProvider)
{
if (lifetimeScopeProvider == null) throw new ArgumentNullException("lifetimeScopeProvider"); LifetimeScopeProvider = lifetimeScopeProvider;
} static void OnEndRequest(object sender, EventArgs e)
{
if (LifetimeScopeProvider != null)
LifetimeScopeProvider.EndLifetimeScope();
}
}
}
using System.ComponentModel;
using Microsoft.Web.Infrastructure.DynamicModuleHelper; namespace Autofac.Integration.Mvc
{
/// <summary>
/// Container class for the ASP.NET application startup method.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public static class PreApplicationStartCode
{
private static bool _startWasCalled; /// <summary>
/// Performs ASP.NET application startup logic early in the pipeline.
/// </summary>
public static void Start()
{
// Guard against multiple calls. All Start calls are made on the same thread, so no lock needed here.
if (_startWasCalled) return; _startWasCalled = true;
DynamicModuleUtility.RegisterModule(typeof(RequestLifetimeHttpModule));
}
}
}
Autofac.Integration.Mvc分析的更多相关文章
- Autofac.Integration.Mvc.Owin分析
using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Secur ...
- Autofac.Integration.Web分析
using System; using System.Web; using Autofac.Core.Lifetime; namespace Autofac.Integration.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结点下的版本号和当前引用的程序集的版本号不一致!
- ioc初步理解(二) 简单实用autofac搭建mvc三层+automapper=》ioc(codeFirst)
之前在园子闲逛的时候,发现许多关于automapper的文章,以及用aotufac+automapper合在一起用.当然发现大多数文章是将automapper的特点说出或将automapper几处关键 ...
- AutoFac在MVC中的使用
在asp.net mvc控制器中使用Autofac来解析依赖 如下Controller中使用构造函数依赖注入接口IUserService: public IUserService _IUserServ ...
- 记一次autofac+dapper+mvc的框架搭建实践
1,环境 .net framework4.7.2,Autofac,Autofac.Mvc5,sql server 2,动机 公司项目用的是ef,之前留下代码的大哥,到处using,代码没有分层,连复用 ...
- IOC容器-Autofac在MVC中实现json方式注入使用
在你阅读时,默认已经了解IOC和autofac的基本用法, 我在最近的我的博客项目中运用了IOC autofac 实现了依赖注入 由于我的项目时asp.net MVC所以我目前向大家展示MVC中如何使 ...
- 【半小时大话.net依赖注入】(下)详解AutoFac+实战Mvc、Api以及.NET Core的依赖注入
系列目录 上|理论基础+实战控制台程序实现AutoFac注入 下|详解AutoFac+实战Mvc.Api以及.NET Core的依赖注入 前言 本来计划是五篇文章的,每章发个半小时随便翻翻就能懂,但是 ...
随机推荐
- lucene-查询query->PrefixQuery使用前缀搜索
PrefixQuery就是使用前缀来进行查找的.通常情况下,首先定义一个词条Term.该词条包含要查找的字段名以及关键字的前缀,然后通过该词条构造一个PrefixQuery对象,就可以进行前缀查找了. ...
- Maven-pom.xml详解
(看的比较累,可以直接看最后面有针对整个pom.xml的注解) pom的作用 pom作为项目对象模型.通过xml表示maven项目,使用pom.xml来实现.主要描述了项目:包括配置文件:开发者需要遵 ...
- 数据库开发基础-SQl Server 存储过程
存储过程: 存储过程(stored procedure)有时也称为sproc.存储过程存储于数据库中而不是在单独的文件中,有输入参数.输出参数以及返回值等. 在数据库中,创建存储过程和创建其他对象的过 ...
- 【LintCode】链表求和
问题分析: 我们通过遍历两个链表拿到每个位的值,两个值加上前一位进位值(0或者1)模10就是该位的值,除以10就是向高位的进位值(0或者1). 由于两个链表可以不一样长,所以要及时判断,一旦为null ...
- iOS二维码扫描IOS7系统实现
扫描相关类 二维码扫描需要获取摄像头并读取照片信息,因此我们需要导入系统的AVFoundation框架,创建视频会话.我们需要用到一下几个类: AVCaptureSession 会话对象.此类作为硬件 ...
- 【BZOJ-3262】陌上花开 CDQ分治(3维偏序)
3262: 陌上花开 Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 1439 Solved: 648[Submit][Status][Discuss ...
- 【vijos1900】 学姐吃寿司
https://vijos.org/p/1900 (题目链接) 题意 给出一个01环,问最少经过多少次相邻互换使得所有的0聚在一坨,所有的1聚在一坨. Solution 源自:LCF Solution ...
- Linux解压命令(tar)
tar zxvf phddns_raspberry.tgz tar默认解压到当前目录 参数: 运行tar时必须要有下列参数中的至少一个才可运行 -A, --catenate, --concatenat ...
- TortoiseGit与GitHub项目关联设置
一.常规克隆GitHub上的项目: 1.在本地硬盘上放置项目的地方上[右键]->[Git 克隆]->在[url地址]上输入https的GitHub的链接,然后就是等待完成,之后即可完成拉取 ...
- Scala特性: 隐式转换
1.隐式转换特征: 1)隐式参数的用法 · 获取可能的预期类型 · 获取预期类型,并且拥有预期类型的行为 · 对信息进行补充说明(一般用函数做隐式参数的比较多) 2)隐式类: 3)隐式method: