variable size list of connection strings in cscfg

180 views Asked by At

I have an Azure Service and I'm using .cscfg files for my configurations. When my service loads the .cscfg, it expects to have there at least 1 connection string.

The problem is, more connection strings may be added later to the cscfg file and I do not want to change my code in order to handle them too.

I couldn't find a way to write the cscfg in a way that it'll build a list of connection strings. Do you know if this is possible? if not, what would you suggest I do? How would I process all the connection strings without changing the code every time that I add another connection string to the cscfg?

Thanks a lot .

1

There are 1 answers

0
Gaurav Mantri On BEST ANSWER

I couldn't find a way to write the cscfg in a way that it'll build a list of connection strings. Do you know if this is possible?

Unlike app/web.config files where you have a dedicated ConnectionStrings element, it is NOT possible to do the same with a service config file. As far as settings are concerned, it is simple name/value pair.

How would I process all the connection strings without changing the code every time that I add another connection string to the cscfg?

Just thinking out loud, you could possibly save all the connection strings in a serialized JSON array and have just one key named something like ConnectionStrings and have your code parse this JSON array and create different connection strings based on the keys in this JSON array.