I am currently injection the concrete ConfigFileSettings of the IConfigFileSettings into classes that require a name for the connection string. The simplified code looks as follows:
public interface IConfigFileSettings
{
string GetConnectionString(string name);
}
public class ConfigFileSettings : IConfigFileSettings
{
public string GetConnectionString(string name)
{
return ConfigurationManager.ConnectionStrings[name].Name;
}
}
This works fine for webapi's hosted in iis, windows services and console application. I guess:
ConfigurationManager.ConnectionStrings[name].Name
won't work in worker roles. Can I adapt the GetConnectionString method to make it work in all environments transparently? Also even if I get the connection sting name (e.g. from a .cscfg file) my code will look for:
<connectionStrings> ... </connectionStrings>
I guess I cannot just add an entry into the .cscfg file?