How do I find out when the Spring.NET root context has loaded?

一笑奈何 提交于 2020-01-04 05:26:28

问题


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?


回答1:


if possible, remove that call to ContextRegistry.GetContext(). That is a sign of bad design anyway because it couples your code very closely to the container - which I think we all agree shouldn't be the case.

What exactly are you trying to do?

P.S: I'd also like to suggest you post Spring for .NET relevant questions to our community forums - it is more likely to get your questions answered there.



来源:https://stackoverflow.com/questions/179140/how-do-i-find-out-when-the-spring-net-root-context-has-loaded

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!