2012-04-19 56 views
4

我想猜測「環境容器」與它是靜態類的事實有關,但這只是一個猜測。來自CommonServiceLocator的此評論中的詞語ambient的含義是什麼?

或者這是指標準模式? (即我真的需要閱讀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; 
     } 
    } 
} 

回答

4

是的,「環境」的解釋是:「共享,提供給大家。」

如果你需要從某處周圍的DI參考,搜索「周圍語境」的格局,在馬克西曼的書「在.NET依賴注入」中描述的。

相關問題