如何在Spring.Net中重新加载上下文

时间:2012-01-10 14:55:08

标签: .net spring.net

我只想知道答案:

using Spring.Context.Support;
...

var context = ContextRegistry.GetContext();
var myObject = (MyObject)context.GetObject("MyObject");

// Making changes to the config file...

???

// Is there a way to reload context 
// so I can have my newly updated object
// without restarting the whole application?

var myObjectWithChanges = (MyObject)context.GetObject("MyObject");

1 个答案:

答案 0 :(得分:1)

您可以使用

context.Refresh();

这将从其持久表示中重新加载所有对象定义(例如xml配置)。

刷新方法不是IApplicationContext接口的一部分,这是您的代码段中context变量的推断类型。然而。它是AbstractApplicationContext的一部分,大多数Spring.net应用程序上下文派生于此。

相关问题