gpt4 book ai didi

c# - CommonServiceLocator 的这条评论中的环境一词是什么意思?

转载 作者:太空狗 更新时间:2023-10-30 01:24:08 29 4
gpt4 key购买 nike

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

或者这是指标准模式? (也就是说,我真的需要从头到尾读完那本 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;
}
}
}

最佳答案

是的,“ambient”应该意味着“共享,所有人都可以使用”。

如果您需要来自 DI 周围某处的引用,请搜索“环境上下文”模式,例如在 Mark Seemann 的“.NET 中的依赖注入(inject)”一书中进行了描述。

关于c# - CommonServiceLocator 的这条评论中的环境一词是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10235461/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com