Seminars

Source code for Jason Dolinger’s Model-View-ViewModel presentation

December 3rd, 2008

Some time back, I posted Jason’s presentation on Model-View-ViewModel and dependency injection with WPF and Unity (if you haven’t checked it out yet, you really should… the stuff there is good for Silverlight, too).  There were numerous requests to take a look at the source code.  It’s now available here.

Jason Dolinger on Model-View-ViewModel

November 6th, 2008

A while back, Jason Dolinger, a consultant here at Lab49, gave us a presentation on design in WPF with the Model-View-ViewModel pattern and the Unity dependency injection framework.

Jason started with an application that one would write in a “traditional” way, with button clicks handled by event-handlers in the code-behind that then updated other parts of the UI. Using WPF data-binding, Commands, and Unity, he transformed it, piece by piece, in a much more manageable, encapsulated, readable, and testable M-V-VM design. It was awesome.

It was so awesome, in fact, that after the presentation Jason recorded the demo for all to see here.

Check it out. It’s the most practically instructive explanation of WPF design I’ve seen.

UPDATE: I thought I should mention that while Jason’s presentation is geared towards WPF, the patterns he describes are very applicable for Silverlight as well. There are a few things to take note of, though:

1) Jason creates ViewModels that are DependencyObjects. For some (apparently undocumented) reason, DataContexts in Silverlight cannot be DependencyObject descendants. That means that you need to implement ViewModels as INotifyPropertyChanged (an option also available for WPF that Jason mentions in his video). This doesn’t fundamentally affect the pattern, but should be noted.

2) Unity, which Jason uses for dependency injection, is available for Silverlight right now as part of pre-release Composite WPF & Silverlight (Prism) v2. You can download it here. (I haven’t been able to find Unity for Silverlight as a separate download.)

3) Silverlight does not support bindings for Commands out of the box. It does, however, expose the ICommand interface. With just a little bit more work using an “Attached Behavior” approach, we can get the kind of Commanding that Jason uses in Silverlight as well. Check out the description here.