Hello all,
I have this:
public interface IRepository<T> where T : class
{
void Delete(T entity);
void Add(T entity);
void Attach(T entity);
void Detach(T entity);
void SaveChanges();
}
now for every of my Entity I make concrete classes implementing the generic IRepository =>
public class SchoolclassRepository : IRepository<Schoolclass>
{
public void Delete(Schoolclass entity)
{
throw new NotImplementedException();
}
public void Add(Schoolclass entity)
{
throw new NotImplementedException();
}
public void Attach(Schoolclass entity)
{
throw new NotImplementedException();
}
public void Detach(Schoolclass entity)
{
throw new NotImplementedException();
}
public void SaveChanges()
{
throw new NotImplementedException();
}
}
In my ViewModel`s constructor (mvvm pattern) I do this =>
IRepository<Schoolclass> repo = new SchoolclassRepository();
What advantage is there with IRepository when I have anyway to write the code for my CRUD operations in every entities class?
In Customer, Product, Pupil whatever class I implement the IRepository<Product>
, IRepository<Customer>
, IRepository<Pupil>
etc... and I implement the methods of the interface.
Why could I not say =>
SchoolclassRepository repo = new SchoolclassRepository(); ???
I do not care for having the possibility to write unit tests for a small app.