I'm fairly new to Silverlight, but I've got my feet wet with a couple apps now. I've run into several issues that I've had to re-train myself on, but I've run into another I need advice and help with.
In the past, with read only lists I have provided a little bit of the "old school" caching by using the approach below:
private
static TosList _list;public
static TosList GetList(){
if (_list == null )
false); return _list;_list = DataPortal.Fetch<TosList>(
}
But now, with Silverlight factory methods, this is less possible due to the callback method used. I realize I could just manually call from codebehind for any of these objects and handle the callback myself instead of letting the CslaProvider do it for me, however, that pushes all of the caching code out of the Business Object and onto the client code....
How are others handling with this?
PS, I also run into this when using the FilteredBindingList class, if I want to simply filter an already fetched object, but expose that as a "Factory Method" on the class, but with a Csla.FilteredBindingList<MyInfo> class...
Here Rocky promotes the use of static caching with Silverlight.
http://forums.lhotka.net/forums/thread/30744.aspx
So it seems it is being done, but is it possible to use static caching with the CslaDataProvider? Perhaps I'm missing something, but the encapsulation of the callback method of the CslaDataProvider seems to prevent this.
Do I need to extend the CslaDataProvider to do this or is there another way?
Remember that CslaDataProvider invokes your factory method. Your factory method has access to the callback handler, and you can add code to do processing during the callback, before letting the data provider get the result.
In fact, you need to do this, so the factory returns the cached value rather than invoking the data portal if there is a valid cached value.
Look at the ProductList class in InventoryDemo for an example.
Ah, I see now! Thanks Rocky!
public
static void GetProductList(EventHandler<DataPortalResult<ProductList>> callback){
if (_cache == null)
{
var dp = new DataPortal<ProductList>();
dp.FetchCompleted += (o, e1) =>
{
_cache = e1.Object;
callback(o, e1);
};
dp.BeginFetch();
}
else{
null, new DataPortalResult<ProductList>(_cache, null, null));callback(
}
}
Is this the best way to provide a FactoryMethod for a filtered list (with filtering performed on the client)? I'm a little shaky with my LINQ, so I presumed the only way to get the proper Type was constructing a list and copying the IEnumerable into the constructed obj (see below)....
public
static void BeginGetFilteredTosList(string category, bool includeInactive, EventHandler<DataPortalResult<TosList>> callback){
//call the normal factory method that gets an unfiltered list
TosList.BeginGetTosList(includeInactive, (o, e) =>{
//now filter it
var filteredList = e.Object.Where(i => i.ServSfxCd == category); TosList result = new TosList();result.IsReadOnly =
false;result.AddRange(filteredList);
result.IsReadOnly =
true;callback(o,
new DataPortalResult<TosList>(result,null,null));});
}
Copyright (c) Marimer LLC