I am considering how to write a repository for a new project.
I like the idea of a generic repository like this for the basic CRUD operations:
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class, IEntity
However, I also read that this is against the spirit of DDD. Therefore as a compromise I was thinking about creating a generic repository and then a few repositories that inherit from it e.g.
CustomerRepository: Repository etc. However, I cannot find any documentation to support this idea.
Q1) Is it a reasonable idea to create a base repository?
Also, I am trying to create one repository per aggregate root rather than one repository per entity. Say I have two classess i.e. Order and OrderItem (Order is the aggresgate root), then:
Q2) Is it reasonable for all the data access for the OrderItem to go in the Order repository (the aggregate root)? i.e.
SELECT * FROM OrderItem WHERE OrderID=@OrderID (translates to LINQ).