Thursday, January 26, 2012

of what bubbles up from repositories

The beauty of the typical repository pattern is you know if something has been "popped off" (forgive my injection of SMTP slang) when you encounter it in another layer. For example consider going into a method and finding:

var bars = foo.Bars;

 
 

If foo is handed in from another method and Bars is a collection of Bar objects on foo, how can we know if the Bars have been lazy loaded by NHibernate yet or not. We can't. We have to start walking upstream to see if there is any place previously in code where foo.Bars was used. Grrr. If there is a policy in which everything that comes over from repositories has already been loaded, then this isn't a problem. A variation of this problem can happen with IQueryable too. When IQueryables are allowed into other layers from the repositories, one does not know, when looking at many spots in code, if an IQueryable had been popped off to a list or not somewhere upstream of the line of code at hand. To counter this pattern, it is probably best to only have objects already cast to lists come over the wall from repositories.

No comments:

Post a Comment