I’m currently extending some existing code that utilizes a lookup table. As it is now the table is about 25 entries and, for better or worse, the key/values are stored in the appsettings section of the web.conf. They are read into a dictionary and used throughout the application.
I’ll be increasing the size of the lookup table to around 300 entries, which is the complete set of values for this domain – so it’s not likely that it will get much larger nor change frequently. I’m not sure that keeping this data in the web.conf is a good idea. A database is not an option for this implementation, so i’m looking for a alternative way to store this data . Some of my thoughts are:
- A static dictionary?
- Xml file (or some other flat external datafile)
- Leaving it in the appsettings section of web.conf?
I’m leaning toward populating a static dictionary in a class that will contain methods for manipulating the dataset. Any advice, comments or cries of outrage would be appreciated.
You can store your additional key value pairs in a config file referenced via the appSettings element – this keeps your main config file neat, and stores the additional config in it’s own dependent config file.
This is explained in the article MSDN – appSettings Element (General Settings Schema).
This is effectively a combination of your second and third items.
I wouldn’t put it in a static dictionary inside the code for maintenance reasons – a config file is a more obvious place for this data too. By leveraging the built in .Net functionality, you also don’t run the risk of someone else ignoring the Xml file for example.
A more concrete example would be (note file paths are relative to the main application):
app.config:
mykeyvaluepairs.config
Note that in your original app.config, it is also okay to do the following:
That is, unless you redefine the appsettings in the mykeyvaluepairs.config file, both will exist side by side – but items with the same name in mykeyvaluepairs.config will override values in the main config.