title: Casting DbContext in UnitOfWork in ASP.NET MVC
body: <p>I've been searching for the Repository and Unit of Work Pattern in C#, and so far this is what I found:</p>
  
  <pre><code>public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T:class
  {
      private DbContext context;
      private DbSet&lt;T&gt; _dbSet;
  
      public Repository(DbContext context)
      {
          this.context = context;
          _dbSet = context.Set&lt;T&gt;();
      }
  }
  </code></pre>
  
  <p>However, in a project that was given to me for study, I saw this one:</p>
  
  <pre><code>public class Repository&lt;T&gt; : IRepository&lt;T&gt; where T:class
  {
      private readonly IUnitOfWork _unitOfWork
      private readonly DbSet&lt;T&gt; _dbSet;
  
      public Repository(IUnitOfWork unitOfWork)
      {
          _unitOfWork = unitOfWork
          _dbSet = ((DbContext)_unitOfWork).Set&lt;T&gt;();
      }
  }
  </code></pre>
  
  <p>Can someone please clarify the difference for me? Any explanation will be highly appreciated. Thanks!</p>