Cant resolve all parts

Feb 1, 2010 at 6:12 AM

Hi,

here my szenario:

First Assembly:

Public Interface IPartA
   Property Somthing1 as ...

Public Interface IPartB
  Property Something2 as ...

Second Assemply holds implementation for IPartA and IPartB, both interfaces were implemented by one class.

Public Class Part
   Implements IPartA
   Implements IPartB

.......

Third Assembly, use this stuff, composes dependencies by MEF

Private myContainer As CompositionContainer
<Import()> Private myPartA As IPartA
<Import()> Private myPartAB As IPartB
.....
Dim catalog As New DirectoryCatalog(.......)
myContainer = New CompositionContainer(catalog)
Dim batch As New CompositionBatch
batch.AddPart(Me)
myContainer.Compose(batch)
The code works fine with IPartA implemented and IPartA resolved, but as far as I try it with the second interface, it fails, even when I implement IPartB within a new class PartB, but 
both classes in one assembly.
Thanks for helping
Gerhard
Developer
Feb 1, 2010 at 3:11 PM

What Export attributes are you placing on your implementation types?

Feb 1, 2010 at 6:20 PM

Oh, sorry, I forgot to post that correct .....

Imports System.ComponentModel.Composition
Imports InterfaceDefinitions

<Export("PartA")> _
Public Class PartA
  Implements IPartA

  Public ReadOnly Property Info() As String Implements InterfaceDefinitions.IPartA.Info

    Get
       Return "I am Part A"
    End Get
  End Property
End Class

originally, I start out with
<Export(GetType(IPartA))> _
and try out some variations, after I run out of ideas ....
Sorry about my bad posting last time
Gerhard
Developer
Feb 2, 2010 at 3:09 PM

So if you wish to import this via the interface IPartA then you will need to export it as Export(GetType(IPartA)) the same goes for IPartB if you want to export it under both interfaces then you will need to put both exports on it.

Feb 2, 2010 at 6:51 PM
Hi ,
I know, how to export and how to import.
I lastly solved the problem today very early in the morning, but can't report earlier, cause of appointments today.
As you try to build a traditional application, which consists of some assemblies, VS2008 automatically generates a build plan based on the dependencies of the projects within a solution. This works nice.
But, when you do MEF, the parts were loosly coupled, there were no dependencies between some projects within a solution, because this is now the job of MEF.
Which of this projects were build first is now of random order, if you were lucky, it works if not you run into the same situation than I.
I do nothing other than 'inject' some dependencies to correct the build plan. I open the 'Project/Project Dependencies' dialog and manually correct the plan.
What a magic, suddenly my sample works, no other changes needed.
Thanks for helping, because I was forced to think more than twice about each detail.
With best regards
Gerhard


Von: weshaggard [mailto:notifications@codeplex.com]
Gesendet: Dienstag, 02. Februar 2010 17:10
An: gerhard.kreuzer@liftoff.at
Betreff: [?? Probable Spam] Re: Cant resolve all parts [MEF:82682]

From: weshaggard

So if you wish to import this via the interface IPartA then you will need to export it as Export(GetType(IPartA)) the same goes for IPartB if you want to export it under both interfaces then you will need to put both exports on it.