zoukankan      html  css  js  c++  java
  • 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);
            }
        }
    }
  • 相关阅读:
    i++与 ++i的 区 别
    css浮动居中实现2
    a MP4Box GUIYamb介绍
    [教程]安装系统解码器 指导教程
    使用AviSynth将高清mov文件导入并重编码为MKV、MP4
    VS2008常用快捷键
    AvsP介绍——非常好用的AviSynth辅助工具
    C/C++语言中Static的作用详述
    [教程]使用Lite MP4 Tool专业制作MP4(AVC)视频格式 指导教程
    Moving Rows in CListCtrl
  • 原文地址:https://www.cnblogs.com/shiningrise/p/5568882.html
Copyright © 2011-2022 走看看