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

  1. Autofac.Integration.Mvc.Owin分析

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

  2. Autofac.Integration.Web分析

    using System; using System.Web; using Autofac.Core.Lifetime; namespace Autofac.Integration.Web { /// ...

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

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

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

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

  5. ioc初步理解(二) 简单实用autofac搭建mvc三层+automapper=》ioc(codeFirst)

    之前在园子闲逛的时候,发现许多关于automapper的文章,以及用aotufac+automapper合在一起用.当然发现大多数文章是将automapper的特点说出或将automapper几处关键 ...

  6. AutoFac在MVC中的使用

    在asp.net mvc控制器中使用Autofac来解析依赖 如下Controller中使用构造函数依赖注入接口IUserService: public IUserService _IUserServ ...

  7. 记一次autofac+dapper+mvc的框架搭建实践

    1,环境 .net framework4.7.2,Autofac,Autofac.Mvc5,sql server 2,动机 公司项目用的是ef,之前留下代码的大哥,到处using,代码没有分层,连复用 ...

  8. IOC容器-Autofac在MVC中实现json方式注入使用

    在你阅读时,默认已经了解IOC和autofac的基本用法, 我在最近的我的博客项目中运用了IOC autofac 实现了依赖注入 由于我的项目时asp.net MVC所以我目前向大家展示MVC中如何使 ...

  9. 【半小时大话.net依赖注入】(下)详解AutoFac+实战Mvc、Api以及.NET Core的依赖注入

    系列目录 上|理论基础+实战控制台程序实现AutoFac注入 下|详解AutoFac+实战Mvc.Api以及.NET Core的依赖注入 前言 本来计划是五篇文章的,每章发个半小时随便翻翻就能懂,但是 ...

随机推荐

  1. Edge Model

    三种edge Step (阶梯) Ramp (坡) Roof 因为噪声的存在, ramp edge是最常见的. 一阶和二阶算子在ramp edge处的表现 一阶和二阶算子对噪声的敏感性 从上自下, 高 ...

  2. poj1984 带权并查集(向量处理)

    Navigation Nightmare Time Limit: 2000MS   Memory Limit: 30000K Total Submissions: 5939   Accepted: 2 ...

  3. html页面中meta的作用

    meta是用来在HTML文档中模拟HTTP协议的响应头报文.meta 标签用于网页的<head>与</head>中,meta 标签的用处很多.meta 的属性有两种:name和 ...

  4. WordPress菜单函数wp_nav_menu()详细介绍

    导航菜单函数wp_nav_menu()进行详细的说明. 1.wp_nav_menu()函数介绍: worpdress发展到3.0以后增加了一个自定义菜单函数wp_nav_menu(),使得wordpr ...

  5. 【BZOJ-1076】奖励关 概率与期望 + 状态压缩DP

    1076: [SCOI2008]奖励关 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1602  Solved: 891[Submit][Status ...

  6. 【BZOJ-3757】苹果树 块状树 + 树上莫队

    3757: 苹果树 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 1305  Solved: 503[Submit][Status][Discuss] ...

  7. 【codevs1993】 草地排水

    http://codevs.cn/problem/1993/ (题目链接) 题意 求有向图最大流. Solution Dinic. 代码 // codevs1993 #include<algor ...

  8. Bzoj2434 [Noi2011]阿狸的打字机

    Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 2536  Solved: 1415 Description 阿狸喜欢收藏各种稀奇古怪的东西,最近他淘到 ...

  9. ecshop /includes/init.php Arbitrary User Login Vul

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对用户输入的cookie,判断免登的逻辑中存在漏洞,导致黑客可以直接通过 ...

  10. Linux 下进程的内存空间分配

    这里主要是以 C 语言为例,其他语言开发的程序,每个进程都会有一个类似的空间.下面是一段 C 代码: #include <stdlib.h> #include <stdio.h> ...