How do you structure config data in a database?

后端 未结 18 1263
后悔当初
后悔当初 2021-01-31 04:37

What is people\'s prefered method of storing application configuration data in a database. From having done this in the past myself, I\'ve utilised two ways of doing it.

18条回答
  •  借酒劲吻你
    2021-01-31 05:01

    My project uses a database table with four columns:

    1. ID [pk]
    2. Scope (default 'Application')
    3. Setting
    4. Value

    Settings with a Scope of 'Application' are global settings, such as Maximum number of simultaneous users.

    Each module has its own scope based; so our ResultsLoader and UserLoader have different scopes, but both have a Setting named 'inputPath'.

    Defaults are either provided in the source code or are injected via our IoC container. If no value is injected or provided in the database, the default from the code is used (if one exists). Therefore, defaults are never stored in the database.

    This works out quite well for us. Each time we backup the database we get a copy of the Configuration which is quite handy. The two are always in sync.

提交回复
热议问题