3

I have a web service running, and it uses Spring.NET for it's IoCness. One of the classes needs to do some stuff when it loads (I'm using AfterPropertiesSet) and "some stuff" involves a call to ContextRegistry.GetContext(). The problem is this code in the 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");    
}

How can I have that object register itself to be notified once the context is fully created?

4

1 回答 1

3

如果可能,请删除对ContextRegistry.GetContext(). 无论如何,这都是糟糕设计的标志,因为它将您的代码与容器非常紧密地耦合在一起——我认为我们都同意不应该是这种情况。

你到底想做什么?

PS:我还想建议您将 Spring for .NET 相关问题发布到我们的社区论坛- 那里更有可能回答您的问题。

于 2009-01-04T11:29:45.383 回答