I have a web application with over 200 configuration settings. These control everything from UI to Business logic.
Should these be retrieved on application startup or when they're needed?
Should they be injected with an ISettings interface when needed.
Whats your opinions?
Update: These can be switched on and off in the application so they are stored in the database. Some are per user settings, and some are application wide. Thoughts now?
I would retrieve it as needed. ASP.NET auto caches this data for you. It is not doing a file read each time. Try changing your web.config file while it's running and you will see that it kills all your sessions and effectively resets your app.
Don't over complicate this. The intent of these settings in the web.config was to be used for settings across the entire application that you need to access. MS has provided you with the libraries to access them and has done the work to make that process as quick as possible. Maybe if you had thousands of settings or something you might be able to find a better caching algorithm but that would be a rare case.
Spend your time on other parts of your code as there is not much to gain in changing how you access the web.config app settings.
Update: If the settings are application wide then use the web.config. If they are user specific and stored in a DB then store them in the user's session at sign in. Some people say to use cookies for user specific settings but if you know who the user is then it is much better to use the session because it prevents a large cookie from being posted back to the server with every request from that user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With