'Configuration settings in (web.config|app.config) versus a Static Class Object
I am just looking at the source code of BlogEngine.Net and was intrigued at how it stores application settings.
Instead of using web.config or app.config which I am accustomed to, the source uses a static class object implemented using a singleton pattern to achieve the application settings. the information is still stored in a settings file but any calls to retrieve information is done via the class object which preloaded all information into property values.
Any advantages of different approaches?
Solution 1:[1]
One serious drawback to this model is the inability to pick up changes made outside the application. As the config settings are loaded at startup and maintained in memory all changes have to be done either through the administration pages or while the application is offline.
Solution 2:[2]
There are pros and cons to having properties that act as config settings accessors.
On one hand, having such a class with properties provides the development team with better organized and more reusable code.
On the other hand, every time you add a new config setting, are you going to have to update the class and rebuild the application?
Solution 3:[3]
From my understanding, the web.config files are loaded into cache upon application start. I haven't looked this up in a very long time so I could be mistaken. If it's true, then I don't really see why a singleton, static class pattern would be beneficial. If the ASP.Net State service or a SQL State Server is used instead of the default in-process session management, restarting of the web app (via IIS or by modifying the config) won't impact sessions. All in all, I'm not entirely certain why blogengine.net would go that route.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Dscoduc |
| Solution 2 | Kon |
| Solution 3 | JamesEggers |
