开发者

c#Repository pattern: One repository per subclass?

I am wondering if you would create a repository for each subclass of a domain model. There are two classes for example:

public class Person
{
    public virtual String GivenName { set; get; }
   开发者_开发百科 public virtual String FamilyName { set; get; }
    public virtual String EMailAdress { set; get; }    
}

public class Customer : Person
{
    public virtual DateTime RegistrationDate { get; set; }
    public virtual String Password { get; set; }        
}

Would you create both a PersonRepository and a CustomerRepository or just the PersonRepository which would also be able to execute Customer related queries?


It really depends on how you domain works. You would usually have one Repository for every Aggregate Root (a DDD term meaning a parent entity, but not in the traditional inheritance way) of your domain.

If you really work with both Person and Customer as part of you domain, then a Repository for each is suitable. A Repository does not need to have a heavy implementation, and Repositories can often share a lot of their implementation, especially when working with an ORM.

This page is a good introduction to the aims of the repository pattern. The Domain Driven Design approach is a good place to start.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜