I have something like following
//Following is the Constructor
public UnitOfWork(IEmployeeContext context)
{
this._context = context;
}
#endregion
public void Dispose()
{
this._context.Dispose();
}
public void Commit()
{
this._context.SaveChanges();
}
public IEmployeeRepository EmployeeRepository
{
{
return _employeeRepository??
(_employeeRepository= new EmployeeRepository(_context));
}
}
Now the Problem is i have another repository which is not based on IEmployeeContext. Lets call that context IOfficeContext so it will be like
get
{
return _officeRepository??
(_officeRepository= new OfficeRepository(_context));
}
The Context passed to OfficeRepository is IOfficeContext . Should i have two separate UnitOfWork for them? or some other clever thing can be done over here?
You could have a common interface:
And have both
IEmployeeContext
andIOfficeContext
inherit from it. ThenUnitOfWork
could know only aboutIContext
and will be able to handle both.