It shows proper way of generating connection strings in a complex and secure environment, using connection-string library.
The demo offers two identical implementations:
It generates a connection string for mongodb, as a good example of handling multi-host connections.
When working with connections, you typically have part of the connection that's static, and part that's dynamic.
For the sake of an example, in this demo we make the following assumptions, and then implement them:
- You have an external/dynamic (or environment-dependent) list of hosts, plus user name and password.
- You know the driver/provider name, plus your database name is static.
- You want to use all connection options statically.
In your application the situation can be quite different, and even completely the other way round. But this demo shows you how to approach this, so you can figure out how to change it to fit your application's needs.
And you can always further complicate the approach, for example:
- make file config.json environment-dependent;
- reload config.json to support dynamic connectivity;
- encrypt password and user name inside config.json
- etc.