title: Implementing this generic repository, unit of work and repository factory
body: <p>I have modifed this a bit, removed one method, from the original post where I found this example. Here is the generic repository. </p>
  
  <pre><code>/// &lt;summary&gt;
  /// Repository base class used with DbContext Originally From http://dotnetspeak.com/index.php/2011/03/repository-pattern-with-entity-framework/
  /// &lt;/summary&gt;
  /// &lt;typeparam name="TContext"&gt;Type of DdContext that this repositiory operates on&lt;/typeparam&gt;
  public class RepositoryBase&lt;TContext&gt; : IDisposable, IRepositoryBase where TContext : DbContext, IObjectContextAdapter, new()
  {
      private DbContext _dbContext;
      public DbContext CurrentContext { get; set; }
  
      /// &lt;summary&gt;
      /// Create new instance of repository
      /// &lt;/summary&gt;
      /// &lt;param name="DbContext"&gt;For embeded edmx resource please define base("name=yourAppEntities") in a class derrived from DBContext&lt;/param&gt;
      public RepositoryBase(DbContext _context)
      {
          _dbContext = new TContext();
          CurrentContext = _dbContext;
      }
      /// &lt;summary&gt;
      /// Select data from database
      /// &lt;/summary&gt;
      /// &lt;typeparam name="TItem"&gt;Type of data to select&lt;/typeparam&gt;
      /// &lt;returns&gt;&lt;/returns&gt;
      public IQueryable&lt;TItem&gt; Select&lt;TItem&gt;()
         where TItem : class, new()
      {
          DbSet&lt;TItem&gt; _set = _dbContext.Set&lt;TItem&gt;();
          return _set;
      }
      /// &lt;summary&gt;
      /// Insert new item into database
      /// &lt;/summary&gt;
      /// &lt;typeparam name="TItem"&gt;Type of item to insert&lt;/typeparam&gt;
      /// &lt;param name="item"&gt;Item to insert&lt;/param&gt;
      /// &lt;returns&gt;Inserted item&lt;/returns&gt;
      public TItem Insert&lt;TItem&gt;(TItem item)
          where TItem : class, new()
      {
          DbSet&lt;TItem&gt; _set = _dbContext.Set&lt;TItem&gt;();
          _set.Add(item);
          _dbContext.SaveChanges();
  
          return item;
      }
      /// &lt;summary&gt;
      /// Update an item
      /// &lt;/summary&gt;
      /// &lt;typeparam name="TItem"&gt;Type of item to update&lt;/typeparam&gt;
      /// &lt;param name="item"&gt;Item to update&lt;/param&gt;
      /// &lt;returns&gt;Updated item&lt;/returns&gt;
      public TItem Update&lt;TItem&gt;(TItem item)
          where TItem : class, new()
      {
          DbSet&lt;TItem&gt; _set = _dbContext.Set&lt;TItem&gt;();
          _set.Attach(item);
          _dbContext.Entry(item).State = System.Data.EntityState.Modified;
          _dbContext.SaveChanges();
          return item;
      }
      /// &lt;summary&gt;
      /// Delete an item
      /// &lt;/summary&gt;
      /// &lt;typeparam name="TItem"&gt;Type of item to delete&lt;/typeparam&gt;
      /// &lt;param name="item"&gt;Item to delete&lt;/param&gt;
      public void Delete&lt;TItem&gt;(TItem item)
         where TItem : class, new()
      {
          DbSet&lt;TItem&gt; _set = _dbContext.Set&lt;TItem&gt;();
          var entry = _dbContext.Entry(item);
          if (entry != null)
          {
              entry.State = System.Data.EntityState.Deleted;
          }
          else
          {
              _set.Attach(item);
          }
          _dbContext.Entry(item).State = System.Data.EntityState.Deleted;
          _dbContext.SaveChanges();
      }
  
  
      /// &lt;summary&gt;
      /// Dipose repository
      /// &lt;/summary&gt;
      public void Dispose()
      {
          if (_dbContext != null)
          {
              _dbContext.Dispose();
              _dbContext = null;
          }
      }
  }
  </code></pre>
  
  <p>How would i implement a DbContext factory for this? As you can see the constructor takes a DbContext, as well when using edmx files compiled in to an assembly you have to pass in a class that derives from DbContext like so:</p>
  
  <pre><code>public class ContextWrapper: DbContext
  {
      public string _connectionString { get; set; }
      public ContextWrapper()
          : base("name=" + ConfigurationManager.ConnectionStrings["MyEFStringName"].Name)
      {
          _connectionString = this.Database.Connection.ConnectionString;
  
  
      }
  }
  </code></pre>
  
  <p>Ignore the _connectionstring get;set; it was for testing.</p>
  
  <p>To me this seems very smelly because of the fact you have to hard code the name of the EF connectionstring name.</p>
  
  <p>I would like to figure out a way to impement a Factory around this that is Generic as well. So we can have a repository generated based on TEntity.</p>