Simple MVVM Toolkit versus MVVM Light Toolkit

Now that I’ve released Simple MVVM Toolkit version 2, people are starting to ask how it stacks up against some of the other MVVM Toolkits out there. (MVVM, which stands for Model-View-ViewModel, is a UI design pattern that provides better maintainability, testability and designability.)  When it comes to deciding which toolkit best suites your needs, there is a spectrum of choices.  On one end are very powerful frameworks, such as Prism or Caliburn (Micro), which offer a plethora of features but have a rather steep learning curve. At the other end there are toolkits that are very lightweight, with the basic features you need to build apps using the MVVM design pattern.

Simple MVVM Toolkit would fall into the latter category.  It is designed with the idea that a design based on simplicity reduces the time spent learning a framework and makes your apps easier to develop and maintain.  But just because a framework is simple does not make it trivial.  In fact, Simple MVVM Toolkit includes just about every feature you need to build real-world line of business apps based on the MVVM design pattern.  However, instead of trying to accommodate every possible use case, my toolkit focuses on the most common scenarios to provide the best possible value with a minimum amount of friction.

So if you need an MVVM toolkit that’s offers basic features and is relatively easy to use, the range of choices narrows to a few options.  Due to time restrictions, I will have to save an exhaustive survey of toolkits for a future post.  But here I will compare Simple MVVM Toolkit to the most popular “basic” toolkit out there: MVVM Light Toolkit by Laurent Bugnion.  Disclaimer: Choice of toolkits depends greatly on your requirements and is a matter of personal preference. This comparison is meant to highlight features and benefits of the Simple MVVM Toolkit and should not be construed as a criticism of any other toolkit.

compare

Platforms

Both Simple MVVM and MVVM Light toolkits support WPF, Silverlight and Windows Phone clients. Both toolkits come with three assemblies offering basically the same functionality, each targeted to a different platform.

Support

The area where Simple MVVM Toolkit really shines in the ease with which you can quickly get up and running.  Presently MVVM Light requires a manual installation, but the download for Simple MVVM is an installer which gives you the assembly binaries, external libraries, samples and source code.  It also registers the toolkit assemblies so that they appear in the Visual Studio Add References dialog, and it installs Visual Studio project and item templates, code and xml snippets.  Everything is there and it just works.  And if you download the Simple MVVM Toolkit from the Visual Studio Extensions Gallery, you’ll also be notified when a new version of the toolkit is released on the gallery.

MVVM Light does not seem to offer much in the way of documentation.  All that’s listed on the Documentation tab of the project are links to a couple blog posts and a few screen shots.  Simple MVVM Toolkit, on the other hand, has Documentation that includes the following topics: Introduction, Features, Prerequisites, Download Contents, Installation, Samples, and a Programming Reference.  In addition there is a Getting Started topic which correlates to a screencast and provides step-by-step instructions for creating a Silverlight app using the toolkit.  I also explore various features of the toolkit on my blog, with a listing posted on the Discussions page of the toolkit project, and I support a Facebook group for the toolkit.

While Laurent lists a number of articles and tutorials that have been written about MVVM Light, I was unable to locate very many samples available for download which demonstrate how to use his toolkit and its various features.  He has presented some workshops for which you can download the code, and there are some tutorials by Jesse Liberty and Chris Koenig.  That’s not too bad, but, perhaps because I prefer to learn by example, I would like to have something more like a reference application.

That is why I have focused a great deal of my energy on building two categories of sample applications that are installed with the Simple MVVM Toolkit.  One is an assortment of small samples, each illustrating a particular feature or aspect of the toolkit: Property Association, Enums, Async, Dependency Injection, Messaging, Navigation, and RIA Services, as well as Getting Started samples for Silverlight, WPF and Windows Phone.  The other category of samples consists of a three-part series showing the development of an end-to-end MVVM Silverlight app that invokes operations on a WCF service and interacts with a SQL Server database.  Part 1 has basic functions and shows how to use events for dialogs and two-way communication between Views and ViewModels.  Part 2 demonstrates navigation, messaging, dependency injection, unit testing and async operations.  Part 3 ports the app to WCF RIA Services and shows how to leverage it for entity persistence and batch updates.

Usability

Both Simple MVVM and MVVM Light toolkits ship with Visual Studio project and item templates, as well as some code snippets.  I would say that the project templates for MVVM Light are rather basic.  There is a ViewModeLocator, which exposes a static MainPageViewModel with a single property and no methods or commands. The MainPage view has a TextBlock that is bound to the property on the MainPageViewModel. That’s it.  Simple MVVM Toolkit also has ViewModelLocator, ViewModel and View classes, but the locator supplies a service agent (represented by an interface), which the ViewModel uses to create a new Model.  In addition Simple MVVM includes a multi-project Visual Studio template that supplies a Silverlight client, a WCF RIA Services web host, and a Unit Testing project.  This is designed to be a real-world example with navigation, modal dialogs, messaging and saving changes. Each project template includes a ReadMe file with step-by-step instructions.

While both toolkits include a number of code snippets, Simple MVVM also sports XML snippets that can be used to add bindings and event triggers to XAML files.

Features

Both toolkits provide a ViewModel base class that implements INotifyPropertyChanged with lambda expressions to support type-safe two-way data binding.  Both toolkits supply a DelegateCommand class for wiring up ViewModel commands.  Commands play a more central role in MVVM Light, which has an EventToCommand behavior, but I favor Blend-style event triggers so that you can call any ViewModel method from any event in the view without all the extra code and funkiness required for commands (for example, SL apps needing to raise the ICommand.CanExecuteChanged event).  I prefer to use commands mainly when you need to pass a parameter to a ViewModel method, which is rare because View elements are generally bound to ViewModel properties.

There are several features included in the Simple MVVM Toolkit which appear to be lacking in MVVM Light. For example, the async support in MVVM Light is simply a wrapper over the Dispatcher, whereas Simple MVVM has async support built right into the ViewModel base class, which transparently marshals to the UI thread when firing the PropertyChanged event.  There is a Notify method for doing the same when communicating with the View using events.

Simple MVVM has two kinds of ViewModels: a general-purpose VM, good for showing summary lists and such, and a “detail’ VM, useful for binding a VM to a single model entity.  The ViewModelDetailBase class has a Model property which you can use to expose the model so that the View can bind directly to it.  This eliminates redundant code in the VM where you need to duplicate each and every model property. The detail VM base class also implements IEditableDataObject with deep cloning and allows you to associate VM properties with one or more model properties, so that updates to the model properties cascade to the associated VM property.

Lastly, Simple MVVM has direct support for dependency injection with MEF (Managed Extensibility Framework) and unit testing (for example with the Silverlight Unit Testing Framework).  In fact, there is an “injected” ViewModel locator item template that allows for mock service agents to be injected into ViewModels when executed by a unit test. The Simple MVVM RIA Services project template includes this code.

Implementation

There is a marked difference between the toolkits in terms of philosophy and style. MVVM Light emphasizes the use of a Messenger for loosely-coupled communication in just about all aspects of the app, including data binding, dialogs and navigation.  Simple MVVM, on the other hand, takes a more pragmatic approach by using events for communication between Views and the ViewModels they own.  The View already knows about its ViewModel, so I don’t see the justification for a message bus in the case of error messages or dialogs.  The VM simply exposes an event and the View subscribes to it, popping up a dialog if needing user input.  It can then communicate the result back to the VM by means of a callback on the event args that are passed in. Simple.

Simple MVVM, like MVVM Light, does include a MessageBus, but there is a different implementation.  MVVM Light allows for any kind of message token and has all kinds of message types – dialog, generic, notification (with and without callback), and property changed.  I chose a simpler approach, allowing only string tokens and a one message type: NotificationEventArgs (with or without callback), which is also used for event-based communication between Views and ViewModels.  The simplicity of this design is its strength: it is both easy to use and it encompasses every kind of communication you would want to perform.

Speaking of ease of use, the ViewModelBase class in Simple MVVM has helper methods for sending and receiving messages.  And the MessageBus uses a leak-proof eventing model, which means you never have to worry about unregistering with the MessageBus.  Subscribers are weakly referenced, so the MessageBus will not prevent them from being garbage collected, thereby avoiding a source of memory leaks. (Note: While the Messenger in v3 of MVVM Light has a bug that causes a memory leak if you fail to unregister, for v4 Laurent intends to use the same leak-proof eventing model as Simple MVVM.)

As you can see, there is a world of difference between the two toolkits, both in terms of design and the feature set, and also in terms of user support.  I designed my toolkit for a broad audience, targeted toward developers who are looking for a simple toolkit that is easy to learn and use, but one that also offers a rich feature set.  By deploying it with an installer (with auto updates from the VS Extensions Gallery and NuGet), documentation, samples and VS templates and snippets, I hope to have helped make your development experience with MVVM more productive and rewarding. Enjoy.

About Tony Sneed

Sr. Software Solutions Architect, Hilti Global Application Software
This entry was posted in Technical and tagged . Bookmark the permalink.

44 Responses to Simple MVVM Toolkit versus MVVM Light Toolkit

  1. powerbala says:

    Nice writeup Tony. I’m still in the learning curve with MvvM, and onetime I gave up’n moved to LightSwitch. Since I finished my demo project I think I’ll give a shot once again to MvvM using your framework.

    Thx! 🙂

  2. robert tuan nguyen says:

    Hi Tony. I’m still in the learning with your framework. I think if I want input validation by using data annotation then where should I do?

    Thanks!

    • Tony Sneed says:

      You can place validation attributes on properties in the metadata class generated when you add a Domain Service. For more info, check out my blog for a webinar I did on WCF RIA Services.

      Cheers,
      Tony

  3. LowTide says:

    Hi Tony,

    I just found your blog and the toolkit is looking good. I have been playing with MVVM Light for a bit and had a hard time finding current examples. I am looking at developing a Silverlight application where I need to use dynamically loaded modules. I planned on using Prism/MEF to get this accomplished. I noticed a post back on Mar 12th in on the CodePlex site you said you didn’t have a specific example of this. Have you had a chance to create one yet?

    TIA

    • Tony Sneed says:

      @LowTide: Yes, To see how my toolkit supports MEF for DI/IoC, check out my screencast and walk-though on Real World MVVM with RIA Services. The steps are on the CodePlex site documentation tab.

      Cheers,
      Tony

  4. Also, a great writeup. Downloaded and am checking it out as I am developing a large LOB application and have been battling with Prism, trying to figure which to use – Mef or Unity. Found your framework and am checking it out. Only problem so far is that the templates were not installed (Mvvm under Silverlight or any of the templates were not installed). What are the steps to manually create a project? I would assume that they are just like any other project and you just add the .dll’s to the appropriate project. Anyway, looks great and I will be checking out. Also, great samples.

    • Tony Sneed says:

      Try downloading the toolkit again from CodePlex, then uninstall and reinstall. There was a glitch in the installer that I fixed a while ago. The templates should get installed. Please let me know if this does not work and I will tell you how to install them manually, but hopefully that won’t be necessary.

      Cheers,
      Tony

  5. Kwaku Fordjour says:

    Thanks for the Simple MVVM toolkit. I have used it in a Silverlight project and appeared to be quite simple, thanks to the abundance of the sample projects. The commanding and messaging infrastructure in the toolkit work quite well.

  6. Maria Castiglione says:

    Where is the best place to ask questions? Is there an official forum yet? I have posted on the Discussion page (I think, I can’t see it maybe it is moderated).

  7. Maria Castiglione says:

    Sorry, I have to move on to a different toolkit. I need one with active users and user forums. Your toolkit had great promise but it was lacking a LOB template. I spent most of yesterday trying to add the authentication functionality from the silverlight LOB template.

    —Maria

  8. MS says:

    Tony, I am curious if you might have any documentation on converting an application that is already using MVVM Light to Simple MVVM?

    • Tony Sneed says:

      Good question! I suppose much depends on how you were using MVVM Light. I don’t specifically address conversion in the docs, but here are the steps I would recommend:

      1) Copy your MVVM Light project so that you have a backup. Then work off the copy to migrate it to Simple MVVM.
      2) Add a reference to SimpleMvvmToolkit
      3) Change the base class for your ViewModels to the ViewModelBase in SimpleMvvmToolkit.
      3) Use the mvvmprop code snippet to overwrite ViewModel properties
      4) Use the mvvmcommand snippet to overwrite ViewModel commands
      5) Call Notify method to ask the View to show dialogs (instead of using the Messenger to do it)
      6) Use SendMessage and RegisterToReceiveMessage methods in the ViewModel base class to send messages between ViewModels

      That should at least get you going in the right direction. Please let me know if this helps.
      Cheers,
      Tony

  9. Pingback: Simple MVVM Toolkit versus MVVM Light Toolkit | XAML | Syngu

  10. Rafael Soteldo says:

    Hi Tony:
    I’m just starting to study MVVM pattern and I run into this two toolkits: the Laurent Bugnion’s MVVMLight toolkit and yours.
    I sense (due to my present lack of knowledge), based on the few readings I’ve made and the fact that I installed and uninstalled MVVM Light and I have recently installed your Simmple MVVM, that yours is more complete.
    However, I saw that MVVM Light adds new templates in Expresion Blend for project creation and your toolkit doesn’t, was my installation of Simple MVVM Toolkit incomplete?

  11. Pingback: Which MvvM for WP7? « Windows Phone 7 Blog

  12. Arya says:

    I am new to MVVM and still in learning curve. I tried both Simple MVVM toolkit and MVVM light, and as a newbie I found your tool kit easier follow. Thanks for this great product.

  13. George Mavritsakis says:

    Hi,
    great work but I need your clarification on the following:

    Is it actually MVVM?

    What I mean is that by MVVM we mean Model – View – ViewModel.
    It appears that with this toolkit you have merged Model and ViewModel actually into the same concept.
    You have view logic in the Model (as you have property changes events) and also you expose the Model type (properties from the Model) to the View .
    That means, that changing a model property name will break the View.

    Please update me,
    overall it is a great work which can target many systems, as long as, truly separation between the Model and the View is not actually needed.

    Thanks!

    • Tony Sneed says:

      Hi George,

      Great observation. There are two main scenarios when it comes to the “Model” in MVVM. One is when I, the developer, am not responsible for creating the model classes. They may be handed to me as code, or I may reference them in a separate assembly. In this case, they may have properties that have nothing to do with what is displayed to the user, and I should have separate detail view models that are bound to the UI. Simple MVVM Toolkit supports this scenario with the DetailViewModel item template.

      The other scenario is when the developer is responsible for the model entities, and there is virtually no difference between properties in the model classes and what is presented to the user. In this case, maintaining two nearly identical sets of classes introduces unnecessary redundancy, and it is sometimes cleaner and more efficient to unify model and detail view model classes. Because I’m a big fan of simplicity, I tend to favor this approach when it is feasible. However, I’m not against the first approach when the model classes are supplied or differ dramatically from detail view model classes. Simple MVVM Toolkit supports both approaches, and you can choose which one makes most sense for your requirements.

      Cheers,
      Tony

  14. surya says:

    Excellent post Tony. I have installed Simple MVVM and planning to use it in SharePoint WebParts. Shortly I will provide my feed back.

  15. G Lanphear says:

    Tony,

    What would I do with the viewmodel and mock viewmodel if I wanted to set up a series of tests, some of them using mock data and some of them using real data on a test server?

    • Tony Sneed says:

      Hi,

      What you’re describing is built right into the toolkit, and it’s what the InjectedViewModelLocator is all about. It has a property that lets you toggle back and forth between “real” and “mock” service agents. The way it distinguishes between the two is an attribute used by MEF (Managed Extensibility Framework), which you place on each of the service agents. You can have some tests where you set the service agent type to Mock, and others where you set it to Real. For more info, go to the toolkit documentation and look at the section on ServiceAgentExportAttribute, IServiceAgentMetadata, AgentType.

      Cheers,
      Tony

  16. Thanks Tony, I like what I’ve seen so far. I only wish I would have found this/you 8 months ago. I’m up to my neck in a project that I decided to use MVVM Light for and I’ve really struggled with the lack of documentation and samples. I’m considering converting, but due to the size of my project I’m not sure it would be wise.

    Anyway, thanks for the great work. I’m going to experiment with your toolkit a bit and see where it leads.

    — Matthew

  17. SAASAASAS says:

    Thanks Tony, I like what I’ve seen so far. I only wish I would have found this/you 8 months ago. I’m up to my neck in a project that I decided to use MVVM Light for and I’ve really struggled with the lack of documentation and samples. I’m considering converting, but due to the size of my project I’m not sure it would be wise.

    Anyway, thanks for the great work. I’m going to experiment with your toolkit a bit and see where it leads.

    – Matthew

  18. Max says:

    Is there a more generic messaging system (like what mvvvm-light has) that allows arbitrary classes to send messages (of any type) to other arbitrary classes?

    Thanks

    • Tony Sneed says:

      Simple MVVM Toolkit supports the sending of messages between any two classes, in much the same way that MVVM Light does. The key is for one class to register to receive messages using a string token, and for another class to send messages using that same token.

      • Max says:

        Tony,
        Thank you for your quick answer. The classes I want to send/receive messages from are not necessarily ViewModels. Although in my case, one is and one is a non-GUI related class.

        From your documentation on the MessageBus:
        “To make it easy to send and receive messages via the MessageBus, ViewModelBase has two helper methods: RegisterToReceiveMessages and SendMessage. ”

        If that classes are not derived from ViewModelBase, then this won’t work? Am I missing something?

        BTW Thanks for the framework!

      • Tony Sneed says:

        Those are just helper methods in the ViewModelBase class. There is nothing to stop you from sending and receiving messages from any class by interacting with the MessageBus directly. Give it a try!

      • Max says:

        Tony,
        Again, thanks. So the register method needs to register an instance of an object that derives from INotifyable? Do I have that right?

        Thanks

      • Tony Sneed says:

        Yes, that is correct. The receiving object needs to implement INotifyable. I wrote this blog post on the message bus, but that was before I refactored it to be leak-proof. ViewModels implement the proxy pattern so that failing to call UnRegister will not cause a memory leak. However, I still recommend that you explicitly call UnRegister for cleaner code and more consistent behavior.

        Tyically the receiver would call Register on MessageBus.Default in its ctor, and UnRegister in a Dispose method. Download this sample to see it in action.

      • Max says:

        Thank you

  19. Rich P says:

    Grettings, I downloaded SimpleMvvmInstaller-v4.0.0.0-new for VS2012 Pro on windows 7 for WPF projects. On the codeplex page I selected the download for WPF/VS2012 pro (I also have mvvmLIght Installed). After installing it (and restarting VS2012) in the (C#/Windows) project templates I see the mvvmLight for WPF but I do not see simplemvvm for WPF. I did see simplemvvm in the Silverlight section. Does this version of simplemvvm which I downloaded support WPF?

    • Tony Sneed says:

      The 2012 version of Simple MVVM Toolkit does support WPF. Under the Windows category, you’ll see an Mvvm subcategory, which contains the SimpleMvvmWpf project template.

      • Rich P says:

        Hi Tony, Thank you for getting back to me on this issue. Here is a picture of the project templates under the Windows category of my VS2012 Pro suite. I don’t see Simple mvvm templates here. Is it maybe something obscure with my VS2012 ? or maybe there is a problem on my end? Or maybe not my end? Note the picture below this one — in the Silverlight category I do see Simple Mvvm templates. I’m just starting out with WPF mvvm, and simple mvvm toolkit seems a little more up my alley than mvvmLight. I hope I can get it to work. Date: Sat, 19 Jul 2014 13:02:29 +0000 To: rpng123@hotmail.com

      • Tony Sneed says:

        Here is a screen shot of the New Project dialog showing the Simple Mvvm WPF template. It is located under Windows / Mvvm. You can also find it by typing mvvm into the search box (Ctrl+E).

        Simple Mvvm WPF Template

        If you still don’t see it, it’s probably because the location of your user project templates is in a non-default location. By default, they are installed here: C:\Users\*Your Name*\Documents\Visual Studio 2012\Templates\ProjectTemplates. You can see where VS is looking by selecting Tools, Options, Projects and Solutions, and checking the “User project templates location”.

      • Rich P says:

        Hi Tony, Thank you. Yes, I found SimpleMvvmWPF.zip in the path you suggested — in Windows Explorer. Do I need to unzip it? How do I get the template to display in the VS2012 New Project Templates window?

  20. Rich P says:

    I left out — yes it is in …Windows\MVVM\SimpleMvvmWPF.zip, but in VS2012 New Project Templates window — under the Windows category — I do not see MVVM. How can I make that appear?

  21. Rich P says:

    Nevermind :). I guess I needed to expand the Windows category. Everything is there — MVVM, SimpleMvvmWPF toolkit.
    Many Thanks for your help.

  22. ac160006 says:

    Nice framework. Looking forward to using it, if I can get it installed. Can’t find the “installer” program. All I see are SimpleMvvmToolkit.VS2013-5.5.0.1 and some other files. I’ve copied them down and installed the VSIX, Also downloaded from “Extensions and Update”. But can’t find the template when creating a new project.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.