Mzf
Mzf

Reputation: 5260

Configuration priority - best practise

When creating a new application that has some configuration. The configuration can exist in one of the following places

The question is what is the priority between them? For example, if I pass a configuration from the command line it will override the config file value for this configuration

Upvotes: 4

Views: 537

Answers (1)

gsone
gsone

Reputation: 1231

So to me the priority is in that order from high to low:

command line (overrides everything bellow), environment variable, config file and default.

In general command line arguments should be able to override all config values.

Environment variables should be able to override config file values but not command line arguments. If you want to override config file value with environment variable then: X=3 that overrides config file value X=1 and then with X=2 should be done via the command line.

I think that is the most flexible way to manage this kind of hierarchy.

Upvotes: 5

Related Questions