How to dynamically configure the application?

When I say “configure”, I mean where you can save the values ​​that can change very often (constant values ​​like tax rates or something like that), and then when you need to change them, you don’t want to Re-compile your application.

Where to save these values? Database? XML file? Flat file?

+4
source share
6 answers

It depends on how often these changes are and who or what changes them. For some specific application parameters, it is best to use an XML or config file in which developers are responsible for updating it. For other "business" values ​​(for example, exchange rates, tax rates, etc.), it is best to store them in a database and provide a user interface for users (not developers) to update.

It also depends on how many applications depend on this value, for example, if several applications depend on some parameters (for example, the email server address), it is best to place it in the database, since it will be easily accessible from anywhere where the application is running .

+3
source

I use INI files for potentially user-configurable files and BIN files for data that maintains session state between runs.

But it really depends on what type of application you are developing.

+1
source

it depends on how your application is architecture. You can create your application so that you can change the location of your configuration. just by entering a provider.

0
source

I usually use Ini or XML files if the data is structured.

For applications that already use the database, and you do not want the user to easily change the data, you can use the database.

I almost never use binary data unless you want to obfuscate the data for the user.

0
source

Regardless of the application, you will likely have at least 3 sources of configuration data:

  • Command line flags are typically used to boot the runtime, for example, searching for configuration files, setting debug flags, including paths, classpaths, etc.
  • Configure files, potentially more than one that can override each other. Usually they download your application: connection strings, cache settings, settings for a specific assembly, etc.
  • Manage data in the database. Things like time zones, conversion rates, stable display values, etc. This data should also be versioned in the database (as in the "Data version" field, and not in the version control system). Versions this will save a lot of headaches when you find that you need to change the settings for the new version, but the old release will be broken if you change it.

As a rule, everything that changes at runtime should go to the database. Everything that is sensitive and rarely changes should go into the configuration files, and any hacks should go to the command line (- [no] enable-bug-287438-hack can be very convenient when you need it).

0
source

I prefer the simplicity of a flat ini file. Here's an example of a Setting class that might come in handy.

0
source

All Articles