Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD - Repository per entity or one for everything?

Tags:

First of all there is probably no correct answer, but I'm sure there are people who knows more than me and will be able to assist.

I have 3 entities: User, Blog, Post.

The system can have any number of users.

User can have any number of blogs, but each blog have only one user.

Blog can have as many posts as the user will post, and all posts will be from the same user that owns the blog (i.e. if John owns blog Food, only John can post in this blog). And of course each post have one parent blog.

Then I have the user profile page, where I want to display all the user details, names of all his blogs, and last 5 posts.

I have then a blog page that displays details of the blog, the name of the owner (User) and titles of all posts.

Then I have post page that displays the post details, blog name and owner name.

As you see I have relations between all of them, but none of them can act as aggregate.

Its not that hard to define the entities in code, what I do have issues with is defining the repositories. How much do I need? 3 - one per each entity? 1 - for everything? How do I perform look-up?

For example to get the 5 last posts in the user page. User does not have reference to Posts, instead in holds a container of Blogs where each Blog in turn holds container of Posts. Should I have a method in my repository that accepts the UserID and returns a list of Posts? Or maybe it should be a Service? Also I don't usually perform loading of all the data but instead I have lazy loading. By retrieving an existing User entity, I would not load its blogs unless they are needed (when first time accessed).

Thanks in advance.