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.

26 Responses to “Jason Dolinger on Model-View-ViewModel”

  1. Shawn Says:

    Fantastic. This is the best intro to MVVM I have seen. Keep things like this coming.

  2. Shawn Says:

    Can we download the code somewhere?

  3. Jeremiah Morrill Says:

    I have to say this video was fabulous! I agree with Shawn by saying it is the best intro to MVVM and IoC I’ve ever seen.

    Thank you!

    -Jer

  4. Mark Heath Says:

    Excellent presentation.

  5. Ray Booysen Says:

    Brilliant!

    Jason loves to hit those keys. Ouch! :P

  6. Jeremy Says:

    Very nice presentation ! Thank you very much for your work.

  7. 2008 November 10 - Links for today « My (almost) Daily Links Says:

    [...] Jason Dolingers cast on Model-View-ViewModel [...]

  8. Sabbir Hossain Says:

    Wow! I’m left speechless! Absolutely brilliant presentation. I’ve implemented a WPF project in the M-V-P pattern, and after watching this, have converted it into M-V-VM :D Thanks a great lot for uploading this video.

  9. leilei Says:

    Thanks. What a great presentation!

  10. Daniele Marrone Says:

    Thanks. Great presentation!

  11. Joe Says:

    Superb! Thanks very much.

  12. bitbonk Says:

    Wow! This was really enlighting. This simple and easy to understand video answered all my current questions I had on designing a wpf based application. What a great relief to know it’s all not that hard to build a wpf application that is modular, unittestable and designable. Can I have more like this? Please?

  13. tlbignerd Says:

    I agree, this is an excellent presentation. There is so much here I am also wondering if we can get the final code somewhere.

  14. David V Says:

    Very well done–thank you.

  15. Mark Says:

    Great presentation! Is the code available for download?

  16. Miguel Saez : Model-View-ViewModel Pattern Says:

    [...] comparto el link que me hizo llegar al video, donde se indica el caso de cómo aplicar el patrón para el caso de [...]

  17. Mark S Says:

    I agree with all this Presentation rocks, thank you! Is the code available for download?

  18. Robert Says:

    I’ve tried to recreate the program and you can download it from here:
    http://reyntjes.blogspot.com/2008/12/my-version-of-jason-dollingers.html

  19. Source code for Jason Dolinger’s Model-View-ViewModel presentation » Lab49 Blog Says:

    [...] time back, I posted Jason’s presentation on Model-View-ViewModel and dependency injection with WPF and Unity (if you haven’t checked [...]

  20. Amanda Says:

    This is such a great resource with the best overview of M-V-VM that I’ve seen yet in nearly 4 months of searching/struggling with the WPF learning mountain. Thanks again for doing such a great job!

  21. Serkan Says:

    Good Demonstration. it helped me a lot in understanding ViewModel concept.

  22. Valentin Stoychev Says:

    Just to mention that Unity1.2 has just been released with support for Silverlight2 too – check it out – http://www.codeplex.com/unity

  23. codenet Says:

    awesome! but where’s the code?

  24. Jackson Says:

    This is the holy grail of MVVM instruction because he gives context by starting the old way and refactoring to the proper way which allows us to relate the new constructions to the old constructs. He also covers several different ways of doing it, implementing them all.
    MVP overview
    Routed Events
    ICommand routing through binding
    UnitTesting
    UnitTest Autogeneration
    Datasource Mocking
    Unity Dependency Injection…

    Good god thank you!

  25. kowadis Says:

    It seems the video is missing. Can someone please point out where to get it?

    thanks.

  26. dsimon Says:

    kowadis:

    I have no trouble getting to the video from the link (at the word “here” in the third paragraph). The URL is http://www.lab49.com/files/videos/Jason%20Dolinger%20MVVM.wmv .