using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Security;
using System.Web;
using Autofac;
using Autofac.Integration.Owin; namespace Owin
{
/// <summary>
/// Extension methods for configuring the OWIN pipeline.
/// </summary>
[SecuritySafeCritical]
[EditorBrowsable(EditorBrowsableState.Never)]
public static class AutofacMvcAppBuilderExtensions
{
internal static Func<HttpContextBase> CurrentHttpContext = () => new HttpContextWrapper(HttpContext.Current); /// <summary>
/// Extends the Autofac lifetime scope added from the OWIN pipeline through to the MVC request lifetime scope.
/// </summary>
/// <param name="app">The application builder.</param>
/// <returns>The application builder.</returns>
[SecuritySafeCritical]
[SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
public static IAppBuilder UseAutofacMvc(this IAppBuilder app)
{
return app.Use(async (context, next) =>
{
var lifetimeScope = context.GetAutofacLifetimeScope();
var httpContext = CurrentHttpContext(); if (lifetimeScope != null && httpContext != null)
httpContext.Items[typeof(ILifetimeScope)] = lifetimeScope; await next();
});
}
}
}

Autofac.Integration.Mvc.Owin分析的更多相关文章

  1. Autofac.Integration.Mvc分析

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

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

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

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

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

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

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

  5. AutoFac在MVC中的使用

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

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

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

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

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

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

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

  9. Autofac.Integration.Owin

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

随机推荐

  1. 素数筛 uva 543

    给你一个n求出n由2个奇质因子的和  这2个因子差最大 没有就输出'Goldbach's conjecture is wrong. #include<stdio.h> #include&l ...

  2. Echarts-axislabel文字过长导致显示不全或重叠

    先看两张图 按目前情况,官方并为对axislabel的高度或者宽度做调整.所以解决方案只能从其他方案下手 解决方案有几种 第一种为上图解决方案 设置grid属性定义图的大小来释放空间,使得axisla ...

  3. HTTP协议学习---(三)摘要认证

    Http 摘要认证 这个认证可以看做是基本认证的增强版本,使用随机数+密码进行md5,防止通过直接的分析密码MD5防止破解. 摘要访问认证最初由 RFC 2069 (HTTP的一个扩展:摘要访问认证) ...

  4. dede使用方法----如何转换时间戳

    dede用sql调用一个mysql时间,mysql的时间字段是时间戳展示的,突然不知道咋转换了,有点迷茫,结果找了下,发现其实很简单,直接用dede的就行了,如下: 完整时间:[field:datel ...

  5. Linux的vim三种模式及命令

    一般模式:在Linux终端中输入"vim 文件名"就进入了一般模式,但不能输入文字.编辑模式:在一般模式下按i就会进入编辑模式,此时就可以写程式,按Esc可回到一般模式. 命令模式 ...

  6. navigate连接MySQL报错:navigate your password has expired to log in your must change it using a client that supports

    如图: 终端进入mysql: 第一次show databases的的时候,密码过期了,然后重置密码为12345,再次就可以显示了 参考连接:http://www.jb51.net/article/79 ...

  7. Java中为什么main()中不能创建内部类对象?

    对main方法而言,虽然写在类中,它是游离于任何类之外的,因此某类的非静态内部类对它而言是不直接可见的,也就无法直接访问 . 1:非静态内部类,必须有一个外部类的引用才能创建. 2:在外部类的非静态方 ...

  8. here 文档

    #!/usr/bin/perl -w use strict; my $someURL = 'http://www.perl.com'; my $html = <<EOF; # EOF 可以 ...

  9. dede的安装和配置

    dede的cms通常是,dede作为后台,前台可以自己换一套模版(后台貌似也跟着换掉,或者不换) 安装时候会检查目录读写权限,以及数据库配置 安装后,还需要登录到后台: 配置网站根网址 清除缓存 数据 ...

  10. 【BZOJ-1952】城市规划 [坑题] 仙人掌DP + 最大点权独立集(改)

    1952: [Sdoi2010]城市规划 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 73  Solved: 23[Submit][Status][ ...