Simplifiying the lazy loading of async properties in Silverlight

Simplifiying the lazy loading of async properties in Silverlight

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


Jack posted on Friday, July 10, 2009

Rocky,

Given the example in the FAQ - http://www.lhotka.net/cslanet/faq/LazyLoadedPropertyInSilverlight.ashx

is there any way that can be built in the framework, maybe as part of the FieldManager, as it is fairly generic (especially for loading simple NVL or childBO)

If I provide a 'pleaseLazyLoad' flag and a getMethod to the RegisterProperty would that be enough?

If the GetPropertyXyz method was simple it could also be an optional parameter as it is assummed.

It could also go so far as to assume that any parameters were also properties if they were not specified.

Seems like something that is feasible and handles most of the simple cases and would certainly cleanup/eliminate some of the code I have to write or cut/paste

* a simple one param getMethod means 20 distinct lines of code that with a medium size property name the line of code runs off the screen if not wrapped

* each cut/paste involves 16 replacements

thanks

jack

RockfordLhotka replied on Friday, July 10, 2009

If you can prototype it I'll consider it.

I don't think it will work though. RegisterProperty() is static, and the async callback code needs to run in the context of your actual business object instance, otherwise it can't have that instance raise PropertyChanged to tell the rest of the world that there's actually a property value there.

In fact, the getMethod would need to be attached to your instance, or it couldn't get/set the property values.

The majority of the code you are referencing deals with calling the factory method, and so is exactly the same as what you'd write to do sync lazy loading. The only difference is the 3-4 lines dealing with the async callback, which has very little variation.

But if you can prototype a more streamlined solution, I'm certainly open to it.

Copyright (c) Marimer LLC