Autofac.Integration.Mvc.Owin分析
Posted 吴晓阳
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Autofac.Integration.Mvc.Owin分析相关的知识,希望对你有一定的参考价值。
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分析的主要内容,如果未能解决你的问题,请参考以下文章