我正在尝试将部件的 MEF 组合抽象为类库类,但我在 .Net4.5 RC 中遇到问题,因为 ComposeParts 扩展方法在类库 CompositionContainer 中不可用
我做错了什么或者可能缺少参考?
WCF 服务类工作容器
<Import(GetType(IGenericModelFactory))>
Public Property ModelFactory As IGenericModelFactory
Private _mefContainer As CompositionContainer
Private _catelog As DirectoryCatalog
Public Sub New()
_catelog = New DirectoryCatalog(".")
_mefContainer = New CompositionContainer(_catelog)
_mefContainer.ComposeParts(Me)
End Sub
类库 - 缺少 ComposeParts 方法
Imports System.ComponentModel.Composition.Hosting
Namespace Core.Composition
Public Class CompositionBuilder
Implements IComposeObjects
Public Function CreateContainer() As CompositionContainer Implements IComposeObjects.CreateContainer
Return Activator.CreateInstance(Of CompositionContainer)()
End Function
Public Sub ComposeFromDirectory(directory As String, compositionRoot As Object) Implements IComposeObjects.ComposeFromDirectory
Dim catelog As DirectoryCatalog = Activator.CreateInstance(GetType(DirectoryCatalog), directory)
Dim mefContainer As CompositionContainer = Activator.CreateInstance(GetType(CompositionContainer), catelog)
mefContainer.Composeparts(compositionRoot)
End Sub
End Class
End Namespace