Architecture with NHibernate and Repositories
Posted
by Matthew
on Stack Overflow
See other posts from Stack Overflow
or by Matthew
Published on 2010-04-13T18:29:55Z
Indexed on
2010/04/13
18:43 UTC
Read the original article
Hit count: 368
I've been reading up on MVC 2 and the recommended patterns, so far I've come to the conclusion (amongst much hair pulling and total confusion) that:
- Model - Is just a basic data container
- Repository - Provides data access
- Service - Provides business logic and acts as an API to the Controller
The Controller talks to the Service, the Service talks to the Repository and Model. So for example, if I wanted to display a blog post page with its comments, I might do:
post = PostService.Get(id);
comments = PostService.GetComments(post);
Or, would I do:
post = PostService.Get(id);
comments = post.Comments;
If so, where is this being set, from the repository? the problem there being its not lazy loaded.. that's not a huge problem but then say I wanted to list 10 posts with the first 2 comments for each, id have to load the posts then loop and load the comments which becomes messy.
All of the example's use "InMemory" repository's for testing and say that including db stuff would be out of scope. But this leaves me with many blanks, so for a start can anyone comment on the above?
© Stack Overflow or respective owner