views:

269

answers:

1

I'm creating a Silverlight front end for an existing desktop app written using CSLA. One thing that I'm having trouble with is converting classes like the following:

public class SomeCollection : Csla.ReadOnlyListBase<SomeCollection, SomeObject>
{
    private static SomeCollection _list = null;
    public static SomeCollection GetSomeCollection()
    {
        if (_list == null)
        {
            _list = DataPortal.FetchChild<SomeCollection>();
        }
        return _list;
    }
}

The code is peppered with "SomeCollection.GetSomeCollection()" This won't work on the silverlight side because all DataPortal access is asyncronous, so you have to start with something like the following:

public static void GetSomeCollection(EventHandler<DataPortalResult<SomeCollection>> callback)
{
    DataPortal<SomeCollection> portal = new DataPortal<SomeCollection>();
    portal.FetchCompleted += callback;
    portal.BeginFetch();
}

The callback handler gets called when the data is ready. I can certainly cache the result of this, but in the meantime any SomeCollection.GetSomeCollection() calls will fail.

I've tried blocking until the asynchronous call completes, but I've had no luck so far. That's not a great solution, but I don't know what else to do if SomeCollection.GetSomeCollection() is called before the data has been loaded. the only other option I can think of is to allow SomeCollection.GetSomeCollection() to return null, and then somehow convert all callers to handle null return values

Any thoughts?

(I'm super new to Silverlight and Csla, so it's possible that I'm going about this the completely wrong way)