title: Dependency Inject Sql Connection?
body: <p>Firstly, I'm starting to use StructureMap, but an example in any DI framework will do.</p>
  
  <p>I have a class as so,</p>
  
  <pre><code>public class GeoData
  {
     public List&lt;Country&gt; GetCountries()
     {
        IDbConnection con = new SqlConnection(ConfigurationManager.ConnectionString["GeoDataConnection"])    
        //Sql stuff to return countries from a database
     }
  }
  </code></pre>
  
  <p>It's a simplistic view of what the class actually looks like, but essentially, that's it.</p>
  
  <p>Now, I have a new requirement.  I need to be able to change connectionstring either on class initialization or on method. E.g.</p>
  
  <pre><code>public void Do()
  {
     var geoData = new GeoData();
  
     if(x)
     {
        geoData.ConnectionString = ConfigurationManager.ConnectionString["LIVEGeoDataConnection"]);
     }
     else
     {
        geoData.ConnectionString = ConfigurationManager.ConnectionString["STAGINGGeoDataConnection"]);
     }
  
     geoData.GetCountries();
  }
  </code></pre>
  
  <p>Is there a better solution for this using dependency injection?  How would you you do this using a DI framework of your choice?  </p>