这条来自CommonServiceLocator的评论中,ambient一词的含义是什么?

4
我猜"环境容器"与其作为一个静态类有关,但这只是我的猜测。或者这是指一个标准模型?(我确实需要彻底阅读一下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;
        }
    }
}
1个回答

4

是的,“环境”应该意味着“共享,对所有人可用”。

如果您需要从DI周围某个地方引用,请搜索“环境上下文”模式,例如在Mark Seemann的“依赖注入.NET”书中描述。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接