2012-06-28 30 views
0

我有一個主要的應用程序,將有很多插件。這裏是PluginReader類我主要的應用程序:MEF未加載進口

Public Class PluginReader 
<ImportMany(GetType(IWebPlugin))> 
    Private m_WebPlugins As IEnumerable(Of Lazy(Of IWebPlugin)) 

    Public Sub New() 

    End Sub 

    Public Property WebPlugins As IEnumerable(Of Lazy(Of IWebPlugin)) 
     Get 
      Return m_WebPlugins 
     End Get 
     Set(value As IEnumerable(Of Lazy(Of IWebPlugin))) 
      m_WebPlugins = value 
     End Set 
    End Property 
End Class 

在我的插件我有這樣的代碼:我的插件的出口正確

<Export(GetType(IWebPlugin))> 
<PartCreationPolicy(CreationPolicy.NonShared)> 
Public Class PluginClass 
    Implements IWebPlugin 
    'Code to implement IWebPlugin here 

我的自定義控制因素讀取,我可以看到IWebPlugin出口,但ImportMany沒有被填充。

如果您需要任何澄清,請讓我知道!謝謝!

回答

0

我只好一個撰寫方法添加到PluginReader類。

Private Sub Compose() 

     Dim catalog As AggregateCatalog = New AggregateCatalog() 
     catalog.Catalogs.Add(New DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory & "bin")) 
     Dim container As New CompositionContainer(catalog) 
     container.ComposeParts(Me) 

    End Sub 

這是我的構造函數:

Public Sub New() 
     Compose() 
    End Sub