public static IAppBuilder UseAutofacMiddleware(this IAppBuilder app, ILifetimeScope container)
{
if (app == null)
{
throw new ArgumentNullException("app");
} if (container == null)
{
throw new ArgumentNullException("container");
} return app
.RegisterAutofacLifetimeScopeInjector(container)
.UseAllMiddlewareRegisteredInContainer(container);
}
        private static IAppBuilder RegisterAutofacLifetimeScopeInjector(this IAppBuilder app, ILifetimeScope container)
{
app.Use(async (context, next) =>
{
using (var lifetimeScope = container.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag,
b => b.RegisterInstance(context).As<IOwinContext>()))
{
context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope);
await next();
}
}); app.Properties[InjectorRegisteredKey] = true;
return app;
}
using System;
using Microsoft.Owin; namespace Autofac.Integration.Owin
{
/// <summary>
/// Extension methods for using Autofac within an OWIN context.
/// </summary>
public static class OwinContextExtensions
{
/// <summary>
/// Gets the current Autofac lifetime scope from the OWIN context.
/// </summary>
/// <param name="context">The OWIN context.</param>
/// <returns>The current lifetime scope.</returns>
/// <exception cref="System.ArgumentNullException">
/// Thrown if <paramref name="context" /> is <see langword="null" />.
/// </exception>
public static ILifetimeScope GetAutofacLifetimeScope(this IOwinContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
} return context.Get<ILifetimeScope>(Constants.OwinLifetimeScopeKey);
}
}
}

Autofac.Integration.Owin的更多相关文章

  1. Autofac.Integration.Mvc.Owin分析

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

  2. integration asp.net web api with autofac and owin

    There is an example project showing Web API in conjunction with OWIN self hosting https://github.com ...

  3. Autofac.Integration.Web分析

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

  4. Autofac.Integration.Mvc分析

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

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

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

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

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

  7. autofac + owin + webform + mvc + webapi集成demo

    http://git.oschina.net/shiningrise/AutofacOwinDemo using Microsoft.Owin; using Owin; using System.We ...

  8. Autofc与Mvc,WebForm,Weiapi,Owin整合源码分析

    主要分析一下的几个项目: Autofac.Integration.Mvc Autofac.Integration.WebApi Autofac.Integration.Owin Autofac.Int ...

  9. 要引用这几个才有GetOwinContext与GetAutofacLifetimeScope

    using Owin; using Autofac; using Autofac.Integration.Owin; using System.Web; var owin = this.Request ...

随机推荐

  1. 求割点 poj 1523

    给你一些双向边 求有多少个割点 并输出去掉点这个点 去掉后有几个联通分量 Tarjan #include<stdio.h> #include<algorithm> #inclu ...

  2. Visual Studio Code 添加设置代码段(snippet)

    从VSCode发布以来就在关注,最近已经更新到版本0.10.8,已经支持了插件功能.日常使用编辑器已经由Sublime Text迁移到了VSCode.使用中遇到了这个问题,在网上也没搜到解决方案.记录 ...

  3. JS 弹窗到右下角

    <div id="msg_win" style="display: block; top: 490px; visibility: visible; opacity: ...

  4. Java反序列化测试

    前言:有没有想过,如何将对象进行“加密”后写入磁盘?序列化帮你实现! 1.概念 序列化 (Serialization)将对象的状态信息转换为可以存储或传输的形式的过程.在序列化期间,对象将其当前状态写 ...

  5. C语言之贪吃蛇

    利用链表的贪吃蛇,感觉自己写的时候还是有很多东西不熟悉, 1.预编译 2.很多关于系统的头文件也不是很熟悉 3.关于内存 第一个是.h头文件 #ifndef _SNAKE_H_H_H #define ...

  6. 【POJ-2482】Stars in your window 线段树 + 扫描线

    Stars in Your Window Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11706   Accepted:  ...

  7. BZOJ4720 [Noip2016]换教室

    本文版权归ljh2000和博客园共有,欢迎转载,但须保留此声明,并给出原文链接,谢谢合作. 本文作者:ljh2000作者博客:http://www.cnblogs.com/ljh2000-jump/转 ...

  8. PHPCMS \phpcms\modules\member\index.php 用户登陆SQL注入漏洞分析

    catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述2. 漏洞触发条件 0x1: POC http://localhost/p ...

  9. ECSHOP Inject PHPCode Into ecs_mail_templates table Via \admin\mail_template.php && \includes\cls_template.php Vul Tag_PHP_Code Execute Getshell

    目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 Ecshop后台模版编辑漏洞,黑客可以在获得了后台管理员的帐号密码之后,可以通过在 ...

  10. CSS基础知识真难啊

    CSS层叠样式表Cascading Style Sheets CSS派生选择器(上下文选择器): 后代选择器:h1  strong {color:red;}第一个参数和第二个参数之间的代数是可以无限的 ...