I use EF in my project and I want to implement the repository design pattern, but I want to have one super class which will take care for the Insert / Update / Delete / SaveChanges methods in order to avoid code duplication.
For example, I have these two interfaces ICostTypeRepository and IEmailRepository:
public interface ICostTypeRepository : IDisposable
{
CostType GetCostTypeById(int pId);
CostType GetCostTypeByCode(string pCode);
IEnumerable<CostType> GetCostTypes();
void Insert(CostType pCostType);
void Update(CostType pCostType);
void Delete(CostType pCostType);
void SaveChanges();
}
public interface IEmailRepository : IDisposable
{
Email GetEmailByID(int pId);
IEnumerable<Email> GetEmails();
Email GetEmailByAdress(string pAddress);
void Insert(Email pEmail);
void Update(Email pEmail);
void Delete(Email pEmail);
void SaveChanges();
}
What is the best way of creating an interface (and its implementation in a class) let's call it IDbOperations which will contain the CRUD methods only?
Something like
public interface IDbOperations : IDisposable
{
void Insert(??);
void Update(??);
void Delete(??);
void SaveChanges();
}
What parameters will these CRUD methods take?
IDbOperations<T>, andTwould be the type of class you're using, e.g.IDbOperations<Email>would then have methods likeInsert(Email email)etc.