Async Properties on BO
Old forum URL: forums.lhotka.net/forums/t/6301.aspx
ixman posted on Friday, January 30, 2009
Hi,
Did anybody tried to asynchronously load properties on a business object? Is there a recommended way to do this?
Thank you,
sergeyb replied on Friday, January 30, 2009
I have done this in SL application (because you cannot do this synchronously in SL environment). It was a bit painful, and I am not sure I would recommend this approach unless necessary.
Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation
-----Original Message-----
From: ixman [mailto:cslanet@lhotka.net]
Sent: Friday, January 30, 2009 1:11 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Async Properties on BO
Hi,
Did anybody tried to asynchronously load properties on a business object? Is there a recommended way to do this?
Thank you,
ixman replied on Friday, January 30, 2009
Hi,
I have a BO with a few “fat” properties and the idea is that this BO is in the DataContext of a window where I switch between two pages… The idea was to have the “fat” properties lazy and async, so that when I go to the first page the BO gets the “light” properties without blocking the UI and when I go to the next page it loads the rest of the properties also without blocking the UI.
Thanks,RockfordLhotka replied on Saturday, January 31, 2009
You are probably better off reconsidering your object model a little.
You may consider having different objects for each page of the UI - each step in the use case. Instead of trying to merge everything into a single object with complex properties, make your life simpler and have a set of different objects that work together to achieve the end goal.
You can have methods on your "first" object to start the async load of subsequent objects. That can help keep a good level of abstraction in the UI (so it doesn't have the logic to understand how to create the other objects). Or probably better, the factory methods of the subsequent objects can accept a reference to the "first" object as a parameter.
For example, suppose my first object is OrderDetail. So my first form loads an OrderDetail and binds it for the user. The user clicks something that takes them to another form, that requires loading a much more expensive object (like ProductDetail that includes a Picture property).
The ProductDetail factory method might have this signature:
public static GetProductDetail(OrderDetail order, int itemIndex, ... callback)
The UI can invoke this factory easily enough, but the method signature makes it very clear that this object can only be retrieved after you've got an OrderDetail object and someone has selected some item index.
Copyright (c) Marimer LLC