Normally, I have implemented Repository Pattern using EF. Here I am using list. Can you guys identify any pitfalls here please. Anywhere it can break. Is it okay to check for null in every function itself
public class Repository<T> : IRepository<T>
{
private List<T> storeDatabase;
public Repository()
{
storeDatabase = new List<T>();
}
public IEnumerable<T> All()
{
return storeDatabase;
}
public void Delete(IComparable id)
{
storeDatabase.RemoveAll(a => a.Id.Equals(id));
}
public T GetById(IComparable id)
{
return storeDatabase.FirstOrDefault(i => i.Id.Equals(id));
}
public void Add(T item)
{
if (item==null)return;
storeDatabase.RemoveAll(a => a.Id.Equals(item.Id));
storeDatabase.Add(item);
}
}
Aucun commentaire:
Enregistrer un commentaire