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 ...
随机推荐
- Java中字符串的几个实例
String str=new String("abc");new 对象时,位于堆中,同时看字符串常量中是否有字符串"abc",如果没有,则进行添加,同时进行关联 ...
- js window.open 打开新窗体 参数设置
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- SpringMVC与Struts2区别与比较总结
1.Struts2是类级别的拦截, 一个类对应一个request上下文,SpringMVC是方法级别的拦截,一个方法对应一个request上下文,而方法同时又跟一个url对应,所以说从架构本身上Spr ...
- 查看mysql语句运行时间
show profiles 之类的语句来查看 mysql> show profiles; Empty set mysql> show variables like "%pro%& ...
- python3 连接SQLserver
pymssql 是Python语言用来连接微软 SQL SERVER 数据库的类库,实现了 Python DB API 2.0 .官网介绍. 最简事例: #!/usr/bin/env python # ...
- 【BZOJ-3122】随机数生成器 BSGS
3122: [Sdoi2013]随机数生成器 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 1362 Solved: 531[Submit][Sta ...
- ASM ClassReader failed to parse class file - probably due to a new Java class file version that isn't supported yet
严重: Context initialization failedorg.springframework.beans.factory.BeanDefinitionStoreException: Fai ...
- Servlet与JSP版本历史以及Tomcat支持的版本
查询这个的关键字:Java EE的版本历史. JavaServer Pages (JSP) Java Servlet 参考: https://en.wikipedia.org/wiki/Java_EE ...
- Node 一个简单的HttpServer+Mysql的后台
接收来自客户端的Post参数,通过Mysql查询,并以Json返回需要的信息,直接代码 createServer(); function createServer(){ //使用express创建HT ...
- Simultaneous Tag Editing in IntelliJ IDEA 14.1
If you're involved in web development and, for some reason, you haven't given a ride to IntelliJ IDE ...