I am trying to reorganize my application from repository to entity into repository for each placeholder.
As a basic example, I have the root of the Cars entity. Cars have rental contracts. As far as I can see, contracts do not exist without cars, so cars are the aggregate root.
I am trying to implement a user view that will display every contract in the system (all children of the root objects). Before refactoring, I could just go to my contract repository and get everything. Since the contract store has been deleted (since it is not the root), I now need to pull all the cars from my repository and then get all their contracts.
My repository has an interface
public interface ICarRepository { IQueryable<Car> All { get; } IQueryable<Car> AllIncluding(params Expression<Func<Car, object>>[] includeProperties); Car Find(long id); void InsertOrUpdate(Car car); void Delete(long id); void Save(); }
I was thinking about creating an ICarManagementService and having a GetAllContracts method (possibly with filter options). Would it mean to get all the contracts I need to pull out all the car divisions with their contracts, and then get all the rental contracts associated with them and filter them out?
Then I can transfer this data to the controller and auto-negotiate the contracts, as before.
Is this the best practice?
thanks
Graeme
source share