A little help with the bootstrapper please (VB)

Topics: Bootstrappers & IoC
May 14, 2013 at 12:46 AM
Edited May 14, 2013 at 12:47 AM
Ok, so I'm quite new in VMMV and completely new on MEF.
I've been reading tutorials and guides, but I can't get my app working.

This is my bootstrapper:
Imports Caliburn.Micro
Imports System.ComponentModel.Composition
Imports System.ComponentModel.Composition.Hosting
Imports System.ComponentModel.Composition.Primitives

Public Class AppBootstrapper
    Inherits Bootstrapper(Of MainViewModel)

    Private container As CompositionContainer

    Protected Overrides Sub Configure()
        container = New CompositionContainer(New AggregateCatalog(AssemblySource.Instance.[Select](Function(x) New AssemblyCatalog(x)).OfType(Of ComposablePartCatalog)()))

        Dim batch As New CompositionBatch()

        batch.AddExportedValue(Of IWindowManager)(New WindowManager())
        batch.AddExportedValue(Of IEventAggregator)(New EventAggregator())

    End Sub

    Protected Overrides Function GetInstance(service As Type, key As String) As Object
        Dim contract As String = If(String.IsNullOrEmpty(key), AttributedModelServices.GetContractName(service), key)
        Dim exports = container.GetExportedValues(Of Object)(contract)

        If exports.Count() > 0 Then
            Return exports.First()
        End If

        Throw New Exception(String.Format("Could not locate any instances of contract {0}.", contract))
    End Function

    Protected Overrides Function GetAllInstances(service As Type) As IEnumerable(Of Object)
        Return container.GetExportedValues(Of Object)(AttributedModelServices.GetContractName(service))
    End Function

End Class
This is the main ViewModel (Equivalent of the ShellViewModel for the Example app on documentation):
Imports System.ComponentModel.Composition
Imports System.Collections.ObjectModel
Imports System.IO
Imports System.Text

Public Class MainViewModel
    Inherits BaseViewModel
    Implements IMain

#Region "Fields"

    Private _
        _CurrentDocument As DocumentViewModel,
        _Documents As ObservableCollection(Of DocumentViewModel)

#End Region

#Region "Properties"

    Public Property CurrentDocument As DocumentViewModel
            Return _CurrentDocument
        End Get
        Set(value As DocumentViewModel)
            If Not _CurrentDocument Is value Then
                If Not _Documents.Contains(_CurrentDocument) Then
                    _Documents(_Documents.IndexOf(_CurrentDocument)) = _CurrentDocument
                End If
                SetField(_CurrentDocument, value, "CurrentDocument")
                _CurrentDocument = value
            End If
        End Set
    End Property

    Public ReadOnly Property Documents As ReadOnlyObservableCollection(Of DocumentViewModel)
            Return New ReadOnlyObservableCollection(Of DocumentViewModel)(_Documents)
        End Get
    End Property

#Region "Constructor"

    Public Sub New(ByVal args As String)
        If (args <> vbNullString) Then

        End If
        _Documents = New ObservableCollection(Of DocumentViewModel)
        CurrentDocument = New DocumentViewModel("Untitled.pwn")
    End Sub

#End Region

#End Region

End Class
Can someone tell me why when I run my app (debug mode 'F5') I got this error inside 'GetInstance':
Could not locate any instances of contract Scripting_Machine.MainViewModel.
Notes: BaseViewModel is the same as PropertyChangedBase but with one more function to change the properties and call the 'NotifyPropertyChange' with one line.
May 14, 2013 at 9:16 AM
Im not au fait with MEF but it looks to be that whatever registers your MainViewModel via MEF is not set up correctly. From what I remember there are usually some sort of decorators to go on the class. I think you are looking for is the following if memory serves me correctly (I tend to use Ninject or Caliburn.Micro's SimpleContainer for my injection needs.
Public Class MainViewModel
May 14, 2013 at 9:22 AM
Dean is correct: you have not exported your view model.
Moreover, your view model defines a constructor with a string parameter as the importing constructor. Are you exporting a proper string to allow composition? If not, you can add a parameterless constructor (passing null as args), and remove the ImportingConstructor attribute.
May 17, 2013 at 12:51 AM
Well as I didn't how MEF work (In a naive attempt on my part) to simplify this problem and get the startup of my app working, I try to avoid MEF by the usage of SimpleInjector. Now I realize I have no clue of what I'm supposed to do or why, so I ask you about what I should search on google to understand this and hopefully get my app working and learn some new things.