views:

850

answers:

1

Hi,

I'm having the following "problem". I created a application context file for spring.net. The configuration looks like this:

<spring>
 <context>
  <resource uri="config://spring/objects"/>
 </context>
 <objects configSource="SpringObjects.config" />
</spring>

I was told that if you change something to the application context you don't need to recompile your application to see the changes.

How ever if I change something to the configuration file. No changes are seen. It is still the original data that is visible.

I call the application context like this:

IApplicationContext ctx = ContextRegistry.GetContext();
 ManagementConfigurator configurator = (ManagementConfigurator)ctx.GetObject("ManagementConfigurator");

Sometimes it takes a while for the changes to be visible (even after recompiling the app).

Regards, SD

EDIT: I just found out that you have to restart your application pool. I'll just rephrase my question then: "Can you reload the application context within you application?" Without having to restart the application pool.

+1  A: 

The application pool doesn't have to be restarted, the AppDomain related to your executing code has to be recycled. I don't know if this is an option for you, but if you put the spring objects inside the web.config file instead of in a separate file, and you change the web.config file (by for instance changing the spring configuration inside it), the AppDomain associated will be recycled, which should also mean that your application gets reconfigured again. You could also just change your SpringObjects.config file and 'touch' the web.config after that. (I'm not sure if putting the SpringObjects.config in the bin directory is a good idea, but a change to the bin dir also causes a AppDomain recycle)

You could use the ContextRegistry methods (Clear, and then RegisterContext) programmatically to reload the ApplicationContext, although I would not recommend it.

Raymond Roestenburg