Autofac.Integration.Owin
- 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的更多相关文章
- Autofac.Integration.Mvc.Owin分析
using System; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Secur ...
- 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 ...
- Autofac.Integration.Web分析
using System; using System.Web; using Autofac.Core.Lifetime; namespace Autofac.Integration.Web { /// ...
- Autofac.Integration.Mvc分析
Autofac.Integration.Mvc static ILifetimeScope LifetimeScope { get { return (ILifetimeScope)HttpConte ...
- 使用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结点下的版本号和当前引用的程序集的版本号不一致!
- autofac + owin + webform + mvc + webapi集成demo
http://git.oschina.net/shiningrise/AutofacOwinDemo using Microsoft.Owin; using Owin; using System.We ...
- Autofc与Mvc,WebForm,Weiapi,Owin整合源码分析
主要分析一下的几个项目: Autofac.Integration.Mvc Autofac.Integration.WebApi Autofac.Integration.Owin Autofac.Int ...
- 要引用这几个才有GetOwinContext与GetAutofacLifetimeScope
using Owin; using Autofac; using Autofac.Integration.Owin; using System.Web; var owin = this.Request ...
随机推荐
- JSP 中的 tag 文件
在jsp文件中,可以引用 tag 和tld 文件,本文主要针对 tag 对于tag 文件 1)将此类文件放在 WEB-INF 下,比如 /WEB-INF/tags,tags 是目录,其下可以有多个.t ...
- java 读取数据库中表定义
将数据库中的表信息读取出来 package com.cloud.smartreport.utils; import java.sql.Connection; import java.sql.Datab ...
- 数据库开发基础-SQl Server 变量、运算符、if、while
变量: SQL语言也跟其他编程语言一样,拥有变量.分支.循环等控制语句. 在SQL语言里面把变量分为局部变量和全局变量,全局变量又称系统变量. 局部变量: 使用declare关键字给变量声明,语法非常 ...
- oracle 10g 安装时字符集的选择,和后边的修改
先用system和密码登陆SQLPLUS,然后: 1.用sys登录到oracle中 connect sys/密码 as sysdba; (能直接以sys登陆到sqlplus吗?)2.开始修改编码 sh ...
- css-关于absolute和relative的一些笔记
根据张鑫旭老师的博客,一些笔记留作备忘 1.position:absolute 具有包裹性--包裹性换种说法就是让元素inline-block化,例如一个div标签默认宽度是100%显示的,但是一旦被 ...
- MapReduce基础知识
hadoop版本:1.1.2 一.Mapper类的结构 Mapper类是Job.setInputFormatClass()方法的默认值,Mapper类将输入的键值对原封不动地输出. org.apach ...
- 【BZOJ-1912】patrol巡逻 树的直径 + DFS(树形DP)
1912: [Apio2010]patrol 巡逻 Time Limit: 4 Sec Memory Limit: 64 MBSubmit: 1034 Solved: 562[Submit][St ...
- 【BZOJ-4519】不同的最小割 最小割树(分治+最小割)
4519: [Cqoi2016]不同的最小割 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 393 Solved: 239[Submit][Stat ...
- Birthday-24
2013 LEXUS花样滑冰 和母亲在一起,生日快乐!
- Linux Overflow Vulnerability General Hardened Defense Technology、Grsecurity/PaX
Catalog . Linux attack vector . Grsecurity/PaX . Hardened toolchain . Default addition of the Stack ...