This ASP .NET MVC application implements Entity Framework.
I've declared the repositories in the DbContext like this:
public class CompanyDbContext : DbContext
{
// constructor goes here
public DbSet<Customer> Customers { get; set; }
public DbSet<Order> Orders { get; set; }
public DbSet<CustomerOrder> CustomerOrders { get; set; }
private IGeneralEntityRepository<Customer> customersRepository;
private IGeneralEntityRepository<Order> ordersRepository;
// ...................
}
This way we can declare and initialise CompanyDbContext within a controller and then access the repositories using the CompanyDbContext instance.
Is this correct? Or should I create a separate "Unit Of Work" class to access the repositories?
private CompanyDbContext db = new CompanyDbContext();
this in each controller it builds. – Adam Zuckerman Feb 22 at 2:54