I'm just writing some data access code. I've decided to pass in the name of connection string from the config via constructor injection which the repository then reads and uses to construct a SqlConnectionStringBuilder.
Thinking about it I probably don't need the SqlConnectionStringBuilder but that's a different matter.
Should I be reading the configuration here or should that be confined to client code? Opinions?
public class SqlRepository : IRepository
{
private SqlConnectionStringBuilder _connString;
public SqlRepository(string connectionStringName)
{
var connStringSetting = ConfigurationManager.ConnectionStrings[connectionStringName];
if (connStringSetting == null)
throw new ArgumentException("Could not find connection string in configuration.");
_connString = new SqlConnectionStringBuilder(connStringSetting.ConnectionString);
}
}