I'm trying to build a new application using the Repository pattern for the first time and I'm a little confused about using a Repository. Suppose I have the following classes:public class Ticket{}public class User{   public List<Ticket>AssignedTickets { get; set; }}public class Group{   public List<User> GroupMembers { get;set; }   public List<Ticket> GroupAssignedTickets { get;set; }}I need methods that can populate these collections by fetching data from the database.I'm confused as to which associated Repository class I should put those methods in. Should I design my repositories so that everything returning type T goes in the repository for type T as such?public class TicketRepository{   public List<Ticket> GetTicketsForGroup(Group g) { }   public List<Ticket> GetTicketsForUser(User u) { }}public class UserRepository{  public List<User> GetMembersForGroup(Group g) { }}The obvious drawback I see here is that I need to start instantiating a lot of repositories. What if my User also has assigned Widgets, Fidgets, and Lidgets? When I populate a User, I need to instantiate a WidgetRepository, a FidgetRepository, and a LidgetRepository all to populate a single user.Alternatively, do I construct my repository so that everything requesting based on type T is lumped into the repository for type T as listed below?public class GroupRepository{    public List<Ticket> GetTickets(Group g) { }    public List<User> GetMembers(Group g) { }}public class UserRepository{   public List<Ticket> GetTickets(User u) { }}The advantage I see here is that if I now need my user to have a collection of Widgets, Fidgets, and Lidgets, I just add the necessary methods to the UserRepository pattern and don't need to instantiate a WidgetRepository, FidgetRepository, and LigetRepository class every time I want to create a user, but now I've scattered the concerns for a user across several different repositories.I'm really not sure which way is right, if any. Any suggestions?
Effective Repository in C# - Where to put methods?
c#;design patterns;repository
As it turns out, the first option was the more practical option in this case. There were a few reasons for this:1) When making changes to a type and its associated repository (assume Ticket), it was far easier to modify the Ticket and TicketRepository in one place than to chase down every method in every repository that used a Ticket.2) When I attempted to use interfaces to dictate the type of queues each repository could pull, I ran into issues where a single repository couldn't implement an generic interface using type T multiple times with the only differentiation in interface method implementation being the parameter type.3) I access data from SharePoint and a database in my implementation, and created two abstract classes to provide data tools to the concrete repositories for either Sharepoint or SQL Server. Assume that in the example above Users come from Sharepoint while Tickets come from a database. Using my model I would not be able to use these abstract classes, as the group would have to inherit from both my Sharepoint abstract class and my SQL abstract class. C# does not support multiple inheritance of abstract classes. However, if I'm grouping all Ticket-related behaviours into a TicketRepository and all User-related behaviours into a UserRepository, each repository only needs access to one type of underlying data source (SQL or Sharepoint, respectively).