Silverlight Lazy Loading

Silverlight Lazy Loading

Old forum URL: forums.lhotka.net/forums/t/9141.aspx


wjcomeaux posted on Monday, June 28, 2010

Hey Rocky.

I've been talking with/working with Blake over at CodeSmith and we're trying to wrap up development on the new Silverlight additions and CSLA 4 implementation for the CSLA templates. You are already familiar with the topic regarding the LazyLoadChildren and UseChildren flags but I will reiterate it here because we would like to get some community feedback.

The main issue is lazy loading of objects in Silverlight. As a method to handle this in code generation I came up with a way that would allow the developer to control which objects lazy load their children at the time when the object is declared. Basically, all synchronous factory methods now expose two additional parameters LazyLoadChildren and UseChildren and all asynchronous factory methods expose only the UseChildren flag.

The reasoning behind this is that lazy loading in Silverlight poses a big problem. In code generation we've made LazyLoadChildren = false in all async cases and the programmer can't even specify it when calling the async factory method. So, for Silverilght, lazyloading is removed from the equation.

UseChildren is available in ALL cases; if it is true then child objects are available, if false, referencing a child property will return null -- alternatively it can raise an exception for clarity. In Async world, if UseChildren is TRUE, the child objects would be eager-loaded at the time that the parent object is loaded,. In the Sync world, the child objects are available but can be eager or lazy loaded depending on the value of LazyLoadChildren.

This pattern also make it possible to lazyload some objects but not others and it also makes it so that some objects can be loaded without ever worrying about their children (in cases where you simply want the root but no children for performance reasons).

I've used this in a test silverlight and test web app and it works, so far. I know from talking with Blake that you have some reservations regarding the pattern -- namely the introduction of 1 or two additional boolean parameters to every factory method -- and I'm wondering if you have come up with any alternatives?

Are there any recommendations that could be integrated cleanly in code generation? We are looking for input from anyone in the community. What kind of options would you CodeSmith users want in the templates?

Thanks for any input,
Will

bniemyjski replied on Monday, June 28, 2010

Hello,

Also I took a look at some of these: http://www.google.com/search?q=silverlight+lazy+loading

Thanks

-Blake Niemyjski

Copyright (c) Marimer LLC