Ignore the fact that DbContext in Entity Framework is unit of work right now. I wonder how I can simplify creating repositories in class UnitOfWork because now I must add property to that class each time when I create new repository class? I don't want generic repository class.
public class UnitOfWork
{
private SchoolContext _context = new SchoolContext();
private IDepartmentRepository _departmentRepository;
private ICourseRepository _courseRepository;
public IDepartmentRepository DepartmentRepository
{
get
{
if (this._departmentRepository == null)
{
this._departmentRepository = new DepartmentRepository(_context);
}
return _departmentRepository;
}
}
public ICourseRepository CourseRepository
{
get
{
if (this._courseRepository == null)
{
this._courseRepository = new CourseRepository(_context);
}
return _courseRepository;
}
}
public void Save()
{
_context.SaveChanges();
}
}