我想猜测“环境容器”与它是静态类的事实有关,但这只是猜测。
或者这是指标准模式? (即我真的需要阅读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;
}
}
}
答案 0 :(得分:4)
是的,“环境”应该是指“共享,可供所有人使用”。
如果您需要来自DI周围某处的参考,请搜索“环境上下文”模式,例如Mark Seemann的“.NET中的依赖注入”一书中所述。