0

Previously I've used Autofac with MVVMLight and the CommonServiceLocator in my WPF application. Now I have a scenario where I cannot use either. So I turn to Microsoft MVVM Toolkit instead. But I can't see how/where to use Autofac with that. Basically what I would like to have, is an alternative to MVVMLight's "ViewModelLocator" pattern. Have a static class where I build my Autofac container and then instruct MVVM to use that static class to resolve...

For example currently I can do this in app.xaml.cs:

<viewmodel:ViewModelLocator x:Key="Locator" />

And then in a view I can do like this:

<UserControl.DataContext>
    <Binding Path="SomePath" Source="{StaticResource Locator}" />
</UserControl.DataContext>`

It might be obvious as the docs say but I can't see how to - any pointers on some sample WFP project would be great :)

Werner
  • 1,229
  • 1
  • 10
  • 24

1 Answers1

0

Autofac is an Inversion of control (IoC) container and the MVVM Toolkit doesn't provide any built-in APIs to facilitate the usage of the Ioc pattern.

There is an example of how to use an IoC of your choice, e.g. Autofac or Microsoft.Extensions.DependencyInjection, to register and resolve instances of any class, including view models, in the docs.

mm8
  • 163,881
  • 10
  • 57
  • 88