When to use Constants vs. Config Files to maintain Configuration

configuration

I often fight with myself on whether to put certain keys in my web.config or in a Constants.cs class or something like this.

For example if I wanted to store application specific keys for whatever the case may be..I could store it and grab it from my web config via custom keys or consume it by referencing a constant in my constants class.

When would you want to use Constants over config keys?

This question really applies to any language I think.

Best Answer

Personally I would only use constants as default values, and let them be overridden by values from a configuration file.

If the application takes command line arguments, then those would in turn override the configuration file parameters.

Related Topic