title: Factory pattern returning objects that require other objects that are already created
body: <p>How do I handle the situation when my concrete object that my factory object will return relies on anther object that is already created. </p>
  
  <p>In order for my repository to work, I need to have an instance of a connection object. I do not want to create a new connection object each time a repository is called. How do I handle this situation? Do I pass the connection object into the RepositoryFactory?</p>
  
  <pre><code>IRepository&lt;User&gt; userRepository = RepositoryFactory.GetRepository("user");
  
   public class UserRepository : IRepository&lt;User&gt;
   {
      public DbConnection Connection { get; set; }
  
      public UserRepository(DbConnection connection)
      {
          this.Connection = connection;
      }
   }
  </code></pre>