How to set when all contract names are the same

Topics: Actions & Coroutines
Jan 15, 2013 at 9:18 PM

I want to set an action's target to my EmployeeWorkspaceViewModel.  This object inherits IWorkspace (similar to the HelloScreens sample) and is imported via MEF by importing many IWorkspace.  The problem is that i also have a ClientWorkspaceViewModel which shares the same contract name.

In my bootstrapper:


    Protected Overrides Function GetInstance(ByVal serviceType As Type, ByVal key As String) As Object
        Dim contract As String = If(String.IsNullOrEmpty(key), AttributedModelServices.GetContractName(serviceType), 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


So what happens is that the exports variable pulls multiple results and then only returns the first one.

Both viewmodels are exported using:

Public Class EmployeeWorkspaceViewModel
End Class

I thought to try:

<Export("EmployeeWorkspace", GetType(IWorkspace))>
Public Class EmployeeWorkspaceViewModel
End Class
But then it doesn't import because i'm doing an <importmany(gettype(IWorkspace))>.  I suppose I could resolve this if there was a way to importmany IWorkspace's regardless of the string parameter.