Simple question really,
I am just looking for community support what works best architecturally.
Say, following case: TempData["MySetting"]? Where should I store "MySetting"? Should it be
- in separate class so that the access will be
TempData[Config.MySetting]; - in web.config so that the access is
TempData[ConfigurationManager.AppSettings["MySetting"]; - inline, leave it as string
TempData["MySetting"];? -
in the DB in some constants table, so that
var mySetting = (string)_db.GetConstant("MySetting"); TempData[mySetting];
I would not deal with option 4, just brought it for completeness of the picture.
So what do you suggest and why?
Edit
Question is rather general about constants in asp mvc rather than TempData case.
Thanks.
Do your settings change? Depending on environment you deploy? If yes, then you definitely want to store them in the Web.config file (you could even make a custom section if it’s not as simple as a couple of key/value pairs).
If they’re the same on all the environments you use (including your own development box, the server and any testing/staging machines you might want to deploy) then I would go for the first option: declare a class with a few constants.
As far as storing them in the database goes, it really depends what kind of settings. If you want them to be per-user of your website, then you might end up storing them in your database. Or in case you want to be able to change them (editing the web.config file while the website is running is not the best idea).
I’d try staying away from leaving it as it is, inline.