Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# CommonServiceLocator的评论中的ambient一词是什么意思?_C#_Comments_Common Service Locator - Fatal编程技术网

C# CommonServiceLocator的评论中的ambient一词是什么意思?

C# CommonServiceLocator的评论中的ambient一词是什么意思?,c#,comments,common-service-locator,C#,Comments,Common Service Locator,我想猜测“环境容器”与它是一个静态类这一事实有关,但这只是一个猜测 或者这是指一种标准模式?(也就是说,我真的需要从头到脚地读那本GoF的书) 名称空间Microsoft.Practices.ServiceLocation { /// ///此类为此应用程序提供环境容器。如果 ///框架定义了这样一个环境容器,请使用ServiceLocator.Current ///去拿。 /// 公共静态类ServiceLocator { 私有静态ServiceLocator提供者currentProvi

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

或者这是指一种标准模式?(也就是说,我真的需要从头到脚地读那本GoF的书)

名称空间Microsoft.Practices.ServiceLocation
{
/// 
///此类为此应用程序提供环境容器。如果
///框架定义了这样一个环境容器,请使用ServiceLocator.Current
///去拿。
/// 
公共静态类ServiceLocator
{
私有静态ServiceLocator提供者currentProvider;
/// 
///当前环境容器。
/// 
公共静电消除器电流
{
获取{return currentProvider();}
}
/// 
///设置用于检索当前容器的委托。
/// 
///调用时将返回的委托
///当前环境容器。
公共静态void SetLocatorProvider(ServiceLocatorProvider newProvider)
{
currentProvider=newProvider;
}
}
}
是的,“环境”应该是指“共享的,每个人都可以使用”

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

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;
        }
    }
}