WPF, ViewModels & Autofac

In MVVM there are lots of elaborate ways to make sure our XAML’s DataContext is correctly instantiated, and if you are using IoC then you should be letting the IoC container instantiate your viewmodel, which doesn’t fit naturally into the XAML view paradigm.

An easy way to do this is to create a XAML resource that will resolve your ViewModel for you, via your IoC container.

Many MVVM frameworks offer this feature, but I wanted one to specifically work with Autofac, so I have written on for this purpose.

Here’s my data provider class

[Continue reading]