zoukankan      html  css  js  c++  java
  • Autofac.Integration.Web分析

    using System;
    using System.Web;
    using Autofac.Core.Lifetime;
    
    namespace Autofac.Integration.Web
    {
        /// <summary>
        /// Provides application-wide and per-request containers.
        /// </summary>
        public class ContainerProvider : IContainerProvider
        {
            readonly IContainer _applicationContainer;
            readonly Action<ContainerBuilder> _requestLifetimeConfiguration;
    
            /// <summary>
            /// Initializes a new instance of the <see cref="ContainerProvider"/> class.
            /// </summary>
            /// <param name="applicationContainer">The application container.</param>
            public ContainerProvider(IContainer applicationContainer)
            {
                if (applicationContainer == null) throw new ArgumentNullException("applicationContainer");
                _applicationContainer = applicationContainer;
            }
    
            /// <summary>
            /// Initializes a new instance of the <see cref="ContainerProvider"/> class.
            /// </summary>
            /// <param name="applicationContainer">The application container.</param>
            /// <param name="requestLifetimeConfiguration">An action that will be executed when building
            /// the per-request lifetime. The components visible within the request can be
            /// customised here.</param>
            public ContainerProvider(IContainer applicationContainer, Action<ContainerBuilder> requestLifetimeConfiguration)
                : this(applicationContainer)
            {
                if (requestLifetimeConfiguration == null) throw new ArgumentNullException("requestLifetimeConfiguration");
                _requestLifetimeConfiguration = requestLifetimeConfiguration;
            }
    
            /// <summary>
            /// Dispose of the current request's container, if it has been
            /// instantiated.
            /// </summary>
            public void EndRequestLifetime()
            {
                var rc = AmbientRequestLifetime;
                if (rc != null)
                    rc.Dispose();
            }
    
            /// <summary>
            /// The global, application-wide container.
            /// </summary>
            /// <value></value>
            public ILifetimeScope ApplicationContainer
            {
                get
                {
                    return _applicationContainer;
                }
            }
    
            /// <summary>
            /// The container used to manage components for processing the
            /// current request.
            /// </summary>
            /// <value></value>
            public ILifetimeScope RequestLifetime
            {
                get
                {
                    var result = AmbientRequestLifetime;
                    if (result == null)
                    {
                        result = _requestLifetimeConfiguration == null ?
                            ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag) :
                            ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag, _requestLifetimeConfiguration);
    
                        AmbientRequestLifetime = result;
                    }
    
                    return result;
                }
            }
    
            static ILifetimeScope AmbientRequestLifetime
            {
                get
                {
                    return (ILifetimeScope)HttpContext.Current.Items[typeof(ILifetimeScope)];
                }
                set
                {
                    HttpContext.Current.Items[typeof(ILifetimeScope)] = value;
                }
            }
        }
    }
            /// <summary>
            /// The container used to manage components for processing the
            /// current request.
            /// </summary>
            /// <value></value>
            public ILifetimeScope RequestLifetime
            {
                get
                {
                    var result = AmbientRequestLifetime;
                    if (result == null)
                    {
                        result = _requestLifetimeConfiguration == null ?
                            ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag) :
                            ApplicationContainer.BeginLifetimeScope(MatchingScopeLifetimeTags.RequestLifetimeScopeTag, _requestLifetimeConfiguration);
    
                        AmbientRequestLifetime = result;
                    }
    
                    return result;
                }
            }
    
            static ILifetimeScope AmbientRequestLifetime
            {
                get
                {
                    return (ILifetimeScope)HttpContext.Current.Items[typeof(ILifetimeScope)];
                }
                set
                {
                    HttpContext.Current.Items[typeof(ILifetimeScope)] = value;
                }
            }
  • 相关阅读:
    Ubuntu 安装mono
    关于BigDecimal.ROUND_HALF_UP与ROUND_HALF_DOWN
    android 常用框架
    理解assign,copy,retain变strong
    SQLSERVER2008R2正确使用索引
    除非 Windows Activation Service (WAS)和万维网发布服务(W3SVC)均处于运行状态,否则无法启动网站。目前,这两项服务均处于停止状态。
    Android资源命名规范
    eclipse导入Android项目后,项目的名称变为了主Activity的名称
    日常运维管理技巧一(查看负载 W)
    Shell简介:1分钟理解什么是Shell 脚本语言 解释器 以及编译器和编译语言
  • 原文地址:https://www.cnblogs.com/shiningrise/p/5568880.html
Copyright © 2011-2022 走看看