博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Autofac.Integration.Owin
阅读量:7087 次
发布时间:2019-06-28

本文共 1916 字,大约阅读时间需要 6 分钟。

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
())) { context.Set(Constants.OwinLifetimeScopeKey, lifetimeScope); await next(); } }); app.Properties[InjectorRegisteredKey] = true; return app; }

 

using System;using Microsoft.Owin;namespace Autofac.Integration.Owin{    ///     /// Extension methods for using Autofac within an OWIN context.    ///     public static class OwinContextExtensions    {        ///         /// Gets the current Autofac lifetime scope from the OWIN context.        ///         /// The OWIN context.        /// 
The current lifetime scope.
///
/// Thrown if
is
. ///
public static ILifetimeScope GetAutofacLifetimeScope(this IOwinContext context) { if (context == null) { throw new ArgumentNullException("context"); } return context.Get
(Constants.OwinLifetimeScopeKey); } }}

 

转载地址:http://ygyql.baihongyu.com/

你可能感兴趣的文章
《网站情感化设计与内容策略》一1.3 你好,马斯洛
查看>>
Logic Programming With Prolog学习笔记(一)
查看>>
Java核心技术卷I基础知识3.8.6 中断控制流程语句
查看>>
《Vim实用技巧(第2版)》——2.3 构造可重复的修改
查看>>
恢复高考这些年,关于高考的老照片
查看>>
首届开放科学奖|6个创造性案例示范如何玩转医学大数据
查看>>
《软件功能测试自动化实战教程》—第6章6.4节Action测试输入的参数化
查看>>
如何通过简单的3步恢复Windows 7同时删除Ubuntu
查看>>
网站建设设计前端开发需要学习html和div+css
查看>>
认知应用:大数据的下个转折点
查看>>
jQuery编程的最佳实践
查看>>
《移动优先与响应式Web设计》一下册 序
查看>>
《自己动手做交互系统》——2.3 制作过程
查看>>
《响应式Web设计性能优化》一2.2 追踪Web性能的工具
查看>>
《精益创业UX篇——高效用户体验设计》一第一篇:验证
查看>>
《Spring攻略(第2版)》——1.11 用XML配置自动装配Bean
查看>>
真的超赞!用systemd命令来管理linux系统!
查看>>
Tomcat7.0.26的连接数控制bug的问题排查
查看>>
《移动网页设计与开发 HTML5+CSS3+JavaScript》—— 2.4 微格式
查看>>
《面向机器智能的TensorFlow实践》安装TensorFlow10
查看>>