Reputation: 3528
Let's say i am a customer of a company and that company offers events.
It has a customer table and a event table. For the subscriber. Their is a subscription table (as a junction, with an extra attribute: AccompaniedByPartner).
So i have a Repository for Customers and Events.
But now the problem is for the subscription.
Does subscription has a Repostitory for add, remove, modify and list and a service for PerformJoinSubscription and PerformCancelSubscription? Or does it only have a Service?
Upvotes: 0
Views: 194
Reputation: 9474
To answer questions like these, ask whether the thing can stand on its own or whether it only makes sense in the context of something else. A subscription clearly makes no sense without the customer and event, and hence should not need a repository of its own. In formal terms, only entities that are aggregate roots should have repositories.
Instead, provide a Subscribe method on Event that takes a Customer parameter (or a Join method on Customer that takes an Event, depending on where you'd prefer it to be), and update the internal collection for the association. When you save the modified entity your repository should then also save the changes to the related objects. ORMs like Entity Framework handle this automatically for you.
Upvotes: 3