What is the meaning of the word ambient in this co

2019-06-27 15:43发布

I want to guess that "ambient container" has something to do with the fact that it's a static class, but that's just a guess.

Or is this referring to a standard pattern? (i.e. I really need to read that GoF book cover to cover)

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条回答
可以哭但决不认输i
2楼-- · 2019-06-27 16:25

Yep, "ambient" is supposed to mean "shared, available to everyone".

If you need a reference from somewhere around the DI, search for the "Ambient Context" pattern, described for example in Mark Seemann's "Dependency Injection in .NET" book.

查看更多
登录 后发表回答