Sunday 15 August 2010

.net - POCO objects with lazy loading -


I is new to AAPNet MVC, IOC, Poko, etc. So I should know that it is ok to use this type of architecture

This is my demo project.

project.Core ( assembly referred to by this project )

  public class user {public string name {get ; Set;} public list & lt; UserGroup & gt; UserGroups {get; Set}} public class UserGroup {public string title {get; Set;}} Public Interface IUserService {User GetById (int id); } Public Interface IUserGroupService {List & lt; UserGroup & gt; GetByUser (User User); }  

Good, but how can I use lazy to load this way? Users Groups Every time I'am is getting the user does not want to receive.

My thoughts are to modify my user class like this:

  public class user {public string name {get; Set;} public list & lt; UserGroup & gt; Get UserGroup {{Return_Groups} (_groups = Services.UserGroupService.GetByUser (this)); } Set {_group = value;}}} Public class services {// Unity public in this class is static IUserGroupService UserGroupService {get; Set;}}  

What is the harm to my solution? I do not like that my POCO object uses the IUserGroupService example.

I do not want to get the user group every time.

Then do not bind them together in the object model. It becomes increasingly complicated, as much as you begin to do it.

If you are doing this to give ideas for the same example, then you can create a view modell with a set of information needs.

Note that if you end the user's requirement with a set of consistent information, which can indicate all the related data in an alternative way and then you can decide You may be able to load curious, and save those extra shottrips that do not do any good.


No comments:

Post a Comment