我正在运行一个 Web 服务,它使用 Spring.NET 来实现 IoCness。其中一个类需要在加载时执行一些操作(我正在使用AfterPropertiesSet
)和“一些东西”涉及调用ContextRegistry.GetContext()
。问题是这段代码在ContextRegistry
class:
if (rootContextCurrentlyInCreation)
{
throw new InvalidOperationException("root context is currently in creation. You must not call ContextRegistry.GetContext() from e.g. constructors of your singleton objects");
}
一旦上下文完全创建,我怎样才能让该对象注册自身以得到通知?
如果可能的话,删除该调用ContextRegistry.GetContext()
。无论如何,这都是糟糕设计的标志,因为它将你的代码与容器紧密耦合——我认为我们都同意不应该是这样。
你到底想做什么?
P.S:我还想建议您将 Spring for .NET 相关问题发布到我们的社区论坛 http://forum.springframework.net/- 您的问题更有可能在那里得到解答。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)