Bxf Caching

Bxf Caching

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


JonM posted on Monday, May 30, 2011

I've been playing with a CSLA 4/Silverlight/MVVm project.  One of things I've had trouble with is transitions when loading a new view.  I've found that caching the view part fixed most of the problem except on the first load.  I've modified the BxF source I'm using to support this.  I changed the .ShowView call with an extra overload called 'Cache'.  When this is set to true the generated view is stuffed in a internal dictionary based on the view name.  If the view is already there it is returned instead.  The viewmodel passed in is still bound to it. Does anyone see a problem with doing this?? 

I also have another WPF app I'm working on that is not a CSLA app but could benefit from a MVVM pattern.  It will only ever have 5-8 views ever.  All the viewmodels need to be persisted through the application life cycle.  I'm trying to decide on whether I should make another modficationt to allow for the caching of the viewModel instide of BxF or if I should just build a static class and put all the viewModels in it.  This way I could initialize them in the app startup and reference them from anywhere in the app on the showview call.  Any thoughts or suggestions?

RockfordLhotka replied on Tuesday, May 31, 2011

This thread should really be on http://bxf.codeplex.com

The idea in Bxf is that your provider (the code handling the OnShowView event) should do any/all of this work. Or the view factory.

Who sets that cache parameter? The code that calls the ShowView method? Why would we want code scattered all over the app to know about caching? That seems like a dangerous move, because it distributes this knowledge everywhere.

I don't fully understand your scenario, but it sounds like you have the need to create a usercontrol instance (view), and then when subsequent requests come in to show that view, you would show that same instance instead of creating a new instance.

That's something the view factory would do. Bxf allows you to create a custom view factory so you can override the default view creation.

JonM replied on Thursday, June 09, 2011

I think you are right.  The code that calls ShowView shouldn't be able to decide about caching view it does create scattered code.  I'm trying to deal with an issue where I'm loading plugins dynamically at runtime so it makes it harder to create reusable instances.  I guess I create an attribute to declare whether or not the view should be cached.  Anyway, thanks for the input on this.

Jon

Copyright (c) Marimer LLC