【问题标题】:What is the meaning of the word ambient in this comment from CommonServiceLocator?CommonServiceLocator 的评论中环境一词的含义是什么?
【发布时间】:2012-05-01 09:40:59
【问题描述】:

我想猜测“环境容器”与它是一个静态类这一事实有关,但这只是一个猜测。

或者这是指标准模式? (即,我真的需要从头到尾阅读 GoF 书籍)

namespace Microsoft.Practices.ServiceLocation
{
    /// <summary>
    /// This class provides the ambient container for this application. If your
    /// framework defines such an ambient container, use ServiceLocator.Current
    /// to get it.
    /// </summary>
    public static class ServiceLocator
    {
        private static ServiceLocatorProvider currentProvider;

        /// <summary>
        /// The current ambient container.
        /// </summary>
        public static IServiceLocator Current
        {
            get { return currentProvider(); }
        }

        /// <summary>
        /// Set the delegate that is used to retrieve the current container.
        /// </summary>
        /// <param name="newProvider">Delegate that, when called, will return
        /// the current ambient container.</param>
        public static void SetLocatorProvider(ServiceLocatorProvider newProvider)
        {
            currentProvider = newProvider;
        }
    }
}

【问题讨论】:

    标签: c# comments common-service-locator


    【解决方案1】:

    是的,“环境”应该是指“共享,所有人都可以使用”。

    如果您需要来自 DI 周围某处的引用,请搜索“环境上下文”模式,例如 Mark Seemann 的“.NET 中的依赖注入”一书中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 2011-03-22
      • 1970-01-01
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      相关资源
      最近更新 更多