I’m using Castle Windsor 2.0 for Dependency Injection in my ASP.NET MVC 2 project.
One of my components holds application configuration data and is currently configured as a singleton (the intent is to avoid frequent trips to the database for values that don’t change very often).
<component id="Configuration" service="MyInterface,
MyAssembly" type="MyClass, MyAssembly2" lifestyle="Singleton" />
I just created an administrative site to make changes to the configuration. The original application holds onto the configuration values until the application pool restarts (not a huge surprise). The users will want the ability to apply their changes in a timely manner.
Possible Solutions:
- Decrease lifetime of the application pool
- Have the site admins recycle the app pool if they want an immediate change
- Switch to another DI container
- Use a single website for everything
- Change the singleton to a PerWebRequest
- Create a mechanism that allows the admin interface to notify the application and refresh the singleton
- Make the singleton expire after a set time thus forcing a refresh
I think option 7 (singleton expiration) would be ideal, but after reviewing Castle documentation it would seem that an expiration feature is not yet available. The custom lifestyle seems like a possible solution but I don’t see how I could implement it.
Does anyone have any suggestions on how to implement options 6 or 7? Maybe there is another solution out there?
You could just call a method on the singleton to reload the settings whenever something changes. Or have a timer internal to the singleton that refreshes it.