简体   繁体   中英

variable size list of connection strings in cscfg

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 .

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM