Services are fine, repositories are overrated.
Repositories within Repositories?
I'm working on an eCommerce application and using the repository pattern. I am using the database to store Carts and Cart Items so that customers can come back to their Cart after their session might have expired. Each Cart Item belongs to a Cart and has a Product Option, quantity, etc. And each Product Option belongs to a Product and has its own description, price, etc.
My issue arises on the cart page. I have a Cart Item repository that can retrieve all the Cart Items for a given Cart id from the database. However, each Cart Item has multiple other dependencies like Product and Product Option. For example, if a customer adds an item to his cart with Product Option 1 and Quantity 1, I can't simply display that information to the customer. I need to retrieve the description and price for Product Option 1 from the Product Options table, as well as the description for Product Option 1 from the Products table, and display them to the customer on the cart page.
To keep with the repository pattern, I want my Cart Item repository to use the Product and Product Option repository to retrieve the appropriate information. However, this introduces a problem where I am needing to inject the Product and Product Option repositories into the Cart Item repository. I read somewhere that it is bad practice to inject foreign repositories into another repository.
As a result, I have created a Cart Item service where I inject all of the necessary repositories. However, I feel that this is kind of a cluttered setup, and I would like to stay away from using catch-all service classes as much as possible. Is there a better organization of this that anyone could suggest?
Please or to participate in this conversation.