views:

462

answers:

4

I'm designing a blog architecture on asp.net mvc. Lets say i only have 2 entities: post and comment. do i need a controller and a repository for each one? how goes the mechanism for displaying a post with it's comments? do the post controller looks in the posts repository for the post, then asks the comment controller to retrieve all the comments connected to this post, gets them from the comments controller and passes them to the view? or maybe i should write a service which is responsible for querying both repositories and returning the results to the posts controller, which passes them to the view?

+1  A: 

Perhaps the first thing to note is what features will your blog have and make available for its primary functions :

  • editing
  • subscription
  • comments
  • authenticating users - eg identifying the blog owner and posters.

What other ideas will yourblog have ? Are you going to try out some new Kool ideas that you might not have seen elsewhere ? If so like what ?

The first questions that need answers are your requirements then you can start worrying about architecture and technology stacks and how to codethis or that type questions. Either way your ideas and questions are most eagerly wanted here :)

mP
+1  A: 

I'm not sure what ORM you are using, but I would only have a single repository for Posts. When I ask for a Post, all the comments should be attached (lazily or eagerly loaded depending on specific instance). In DDD terms I think you'd describe it as the Posts entity is the root of the 'Posts' aggregate if you want to view it that way.

I don't think there is anything wrong with having two repositories in a single controller though.

eyston
A: 

You can checkout examples such as

Todd Smith
A: 

You might be interested in this other post discussing ASP.NET MVC + CSLA + DDD . It provides nice examples of projects using them together.

Julien Bérubé