I created my own generic repository class with interface:
public interface IRepository<T>
{
//Retrieves list of items in table
IQueryable<T> List();
IQueryable<T> List(params string[] includes);
//Creates from detached item
T Create(T item);
//Updates from detached item
//Attached item can be change directly and using SaveChanges
T Edit(T item);
void Delete(int id);
void DeleteObject(object item);
T Get(int id);
T Get(int id, params string[] includes);
void SaveChanges();
}
It takes care of basic CRUD operation, it has also context. Over repository i have service classes that hold business login. Example:
public interface IProjectService
{
IQueryable<Project> ListProjects();
Project GetProjectByName(string name);
Project GetProjectByID(int id);
bool EditBasicProjectData(Project project);
bool CreateProject(Project project);
bool DeleteProject(int id);
void SetCurrentProjectByID(int id);
}
Every service has necessary repositories. Controllers have services injected by NInject. Controller methods are short, they are only passing data from services to view (in both ways). That makes whole project easy testable. You can mock repository to test service. You can mock service to test controller.