As per my understanding GenericRepository
is inherited from IGenericRepository
. It has properties as IDbFactory DbFactory
, DBCustomerEntities dbContext
and DBCustomerEntities DbContext
. We are getting the value for DBCustomerEntities dbContext
using Init
method of IDbFactory
, which is actually initialising database.
My question is why constructor GenericRepository
is required and what is its role?
public class GenericRepository<T> : IGenericRepository<T> where T : class
{
private DBCustomerEntities dbContext;
protected IDbFactory DbFactory
{ get; private set; }
protected DBCustomerEntities DbContext
{
get { return dbContext ?? (dbContext = DbFactory.Init()); }
}
public GenericRepository(IDbFactory dbFactory)
{
DbFactory = dbFactory;
}
public IQueryable<T> GetAll()
{
return DbContext.Set<T>();
}