我想猜测“环境容器”与它是静态类这一事实有关,但这只是一个猜测。
或者这是指标准模式? (也就是说,我真的需要从头到尾读完 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;
}
}
}
是的,“环境”应该意味着“共享,每个人都可以使用”。
如果您需要来自 DI 周围某个地方的参考,请搜索“环境上下文”模式,例如 Mark Seemann 的“.NET 中的依赖注入”一书中所描述的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)