我试图将MEF组成部分抽象为类库类,但我在.Net4.5 RC中遇到问题,因为ComposeParts Extension方法在类库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
答案 0 :(得分:2)
看起来您必须包含System.ComponentModel.Composition
命名空间
Imports System.ComponentModel.Composition.Hosting
Imports System.ComponentModel.Composition
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