Okay, I've looked all over and can't find anything in the samples. Only thing I've been able to find regarding usage in Windows 8 is the blog posts about it being released on Nuget. I've copied this code to my App.xaml.cs
var configuration = new ContainerConfiguration().WithAssembly(typeof(App).GetTypeInfo().Assembly);
I've confirmed that when my application starts that I can get instances of the exported classes while stepping through the debugger using
_mefContainer = configuration.CreateContainer();
var viewModel = _mefContainer.GetExport<MainViewModel>();
However, when the default code in OnLaunched runs
if (!rootFrame.Navigate(typeof(MainView), args.Arguments))
It is not using an instance of the view from the container. Here is the my view constructor with export and import attributes for the view model.
[Export] publicsealedpartialclass MainView : Page { public MainView() { this.InitializeComponent(); } [Import] public MainViewModel ViewModel { get { return _viewModel; } set { _viewModel = value; this.DataContext = value; } } private MainViewModel _viewModel;
Any ideas on what I'm doing wrong? I've used MEF with Prism in an WPF appliaction before and had no problems with it so I'm familiar with how to set up the classes to correctly import and export objects. I'm just stumped on how to correctly setup and use the container other than using GetExport<T> everytime - Is that how I'm supposed to do it? Would be great to find a simple Win8 app sample that used MEF.