2012-01-10 58 views
0

重装方面,我只想知道答案:如何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

您可以使用

context.Refresh(); 

此重新加载从他们的持久性陈述所有的对象定义(例如XML配置)。

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