title: Persisting data without a reference
body: <p>I have an a problem in C# where when I want to do a query to the database, I create a new instance of my <code>DBQuerier()</code> and call a <code>Run()</code> method on it.</p>
  
  <p>The <code>DBQuerier</code> can connect to one of several databases, depending on what is passed to the run method - for example new <code>DBQuerier().Run(DBEnum.CatDatabase)</code>;</p>
  
  <p><code>DBQuerier</code> is part of a library as a variety of solutions use it.</p>
  
  <p>I have a configuration file that I can load and parse to get all of the connections loaded into memory, used for the enum lookup. However, I am unsure of how to persist this information. It looks like a job for dependency injection:</p>
  
  <p><code>new DBQuerier(new MyConnectionStringLoader()).Run(...)</code></p>
  
  <p>However I don't want it to load the file and parse it every single time a db query is run in this way. I can't store it within DBQuerier because this object is created and discarded every time.</p>
  
  <p>If I make a ConnectionStringManager class, if it is static then I can't cleanly dependency inject MyConnectionStringLoader into it, and it makes it harder to unit test. If I make it a singleton I have some similar issues.</p>
  
  <p>Is there a good solution for this problem? Googling it has revealed myriad of posts saying 'never use static classes or singleton' so I am pretty stuck.</p>