Avoiding mass propagation of properties and events for exposure to ViewModels.

Posted by firoso on Stack Overflow See other posts from Stack Overflow or by firoso
Published on 2010-06-14T18:02:02Z Indexed on 2010/06/14 18:22 UTC
Read the original article Hit count: 213

Filed under:
|
|
|
|

I have an MVVM application I am developing that is to the point where I'm ready to start putting together a user interface (my client code is largely functional)

I'm now running into the issue that I'm trying to get my application data to where I need it so that it can be consumed by the view model and then bound to the view.

Unfortunately, it seems that I've either got a few structural oversights, or I'm just going to have to face the reality that I need to be propogating events and raising excessive amounts of errors to notify view models that thier properties have changed.

Let me go into some examples of my issue:

I have a class "Unit" contained in a class "Test", contained in a class "Session" contained in a class "TestManager" which is contained in "TestDataModel" which is utilized by "TestViewModel" which is databound to by my "TestView" .... WHOA.

Now, consider that Unit (the bottom of the heiarchy) has a property called "Results" that is updated periodically, I want to expose that to my viewmodel and then databind it to my view, trouble is, the only way I can really think to do this is to perpetuate events WAY up a chain that say "I've been updated!" and then request the new value... This seems like an aweful way to do this. Alternatively, I could register a static event and raise it, and have the appropriate "Unit view model" grab the event and request the update. This SEEMS better... but... static events? Is that a taboo idea?

Also, having an expression like:

TestDataModel.TestManager.Session.Test.Unit.Results[i] Seems REALLY gross to have on a View Model.  

I know this all reeks of a bad design issue, but I can't figure out what I did wrong? Should I be using more singleton/container controlled lifetimes type objects? Register object instances with static helper containers? Obviously these are hard questions to answer without being intimate with the existing structure, but if you've run into situations like this, what did you do to refactor? Should I just live with this, add mass events, and propogate them?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about wpf