Benefit of IoC container in MVVM

Apr 16, 2014 at 2:39 PM
Edited Apr 16, 2014 at 2:40 PM
What is the benefit of IoC container in MVVM Light? What is the benefit of the ViewModelLocator? Why not instantiating the view-models directly in the XAML file like below:
<UserControl>
    <UserControl.DataContext>
        <vm:MainViewModel/>
    </UserControl.DataContext>

    <!-- Other user control elements here -->

</UserControl>
Coordinator
May 11, 2014 at 5:29 PM
There are multiple reasons and I encourage you to read this:

http://msdn.microsoft.com/en-us/magazine/jj991965.aspx

Mainly, the way you use up there gives you zero control on the lifetime of the ViewModel, and also forces you to use parameter-less constructors, which is limiting.

Cheers
Laurent.
Jun 5, 2014 at 11:25 AM
Hello,

First, I'd like to say "Bravo !" for this MVVM Light Toolkit. Real a splendid work.

I'm starting to learn it (discovering MVVM at the same time) and it is very helpful to get samples... :-)
Especially on this IoC topic for which I've not fully understood all the intrincacies.

However, in the above referred article (MSDN) it appears that the sample is no longer available (Archive Gallery has been retired). Would you mind to tell where I can get this Code Sample?

Thanks
Christian
Coordinator
Jun 5, 2014 at 2:31 PM
Hi and thanks for the kind words. I need to talk to the editor of MSDN magazine to see what's up with that.

Cheers
Laurent