I need to distribute some sort of static configuration through my application. What is the best practice to do that?
I see three options:
- Call
application:get_envdirectly whenever a module requires to get configuration value.- Plus: simpler than other options.
- Minus: how to test such modules without bringing the whole application thing up?
- Minus: how to start certain module with different configuration (if required)?
- Pass the configuration (retrieved from
application:get_env), to application modules during start-up.- Plus: modules are easier to test, you can start them with different configuration.
- Minus: lot of boilerplate code. Changing the configuration format requires fixing several places.
- Hold the configuration inside separate configuration process.
- Plus: more-or-less type-safe approch. Easier to track where certain parameter is used and change those places.
- Minus: need to bring up configuration process before running the modules.
- Minus: how to start certain module with different configuration (if required)?
Another approach is to transform your configuration data into an Erlang source module that makes the configuration data available through exports. Then you can change the configuration at any time in a running system by simply loading a new version of the configuration module.