在CommonServiceLocator的评论中,ambient是什么意思? [英] What is the meaning of the word ambient in this comment from CommonServiceLocator?
本文介绍了在CommonServiceLocator的评论中,ambient是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想猜测环境容器与它是一个静态类的事实有关,但这只是一个猜测。
到标准模式? (即我真的需要阅读GoF的封面来覆盖)
命名空间Microsoft.Practices.ServiceLocation
{
///< summary>
///此类为此应用程序提供了环境容器。如果你的
///框架定义了这样一个环境容器,使用ServiceLocator.Current
///得到它。
///< / summary>
public static class ServiceLocator
{
private static ServiceLocatorProvider currentProvider;
///< summary>
///当前环境容器。
///< / summary>
public static IServiceLocator当前
{
get {return currentProvider(); }
}
///< summary>
///设置用于检索当前容器的代理。
///< / summary>
///< param name =newProvider>委托,调用时将返回
///当前环境容器。< / param>
public static void SetLocatorProvider(ServiceLocatorProvider newProvider)
{
currentProvider = newProvider;
}
}
}
解决方案>
是的,环境应该是指共享,可供所有人。
如果您需要来自DI周围的引用,请搜索环境上下文模式,例如Mark Seemann的Dependency Injection in .NET
I want to guess that "ambient container" has something to do with the fact that it's a static class, but that's just a guess.
Or is this referring to a standard pattern? (i.e. I really need to read that GoF book cover to cover)
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;
}
}
}
解决方案
Yep, "ambient" is supposed to mean "shared, available to everyone".
If you need a reference from somewhere around the DI, search for the "Ambient Context" pattern, described for example in Mark Seemann's "Dependency Injection in .NET" book.
这篇关于在CommonServiceLocator的评论中,ambient是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文