Recently I have encountered an article Implement the Query Specification pattern and I am confused about using specification pattern with generic repository.
I have already a generic repo like this:
public interface IGenericRepository<T> where T:class
{
IReadOnlyList<T> GetAllAsunc(int id);
IReadOnlyList<T> FindAsync(Expression<Func<T, bool>> filter);
T GetById(int id)
void Add(T item);
void Update(T item);
void Delete(T item);
}
And a sample method for specification pattern
public BaseSpecification(Expression<Func<T, bool>> criteria)
{
Criteria = criteria;
}
I can send any expression with IReadOnlyList<T> FindAsync(Expression<Func<T, bool>> filter);
method. So, I don't really understand why I need specification pattern with generic repository. It looks they are doing same things. Could you clarify this?