I am trying to implement Unit of Work/Repository pattern in my MVC Web application.
Since DbContext itself is a unit of work, I want to mix it with my own UOW for testing and decoupling purposes (decoupling business layer from EF). Is it then a good idea to just wrap my DbContext
inside an UOW class like the following?
Example:
Code reduced for clarity
public interface IUnitOfWork
{
void Save();
}
public MyContext : DbContext
{
// DbSets here
}
public UnitOfWork : IUnitOfWork
{
public MyContext myContext { get; set; }
void Save()
{
myContext.SaveChanges();
}
}
Then I would call UnitOfWork
instance to perform data operations.
Thanks a lot in advance :-)