Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 如何与mef一起使用另一个ioc容器?_Wpf_Architecture_Prism_Mef_Autofac - Fatal编程技术网

Wpf 如何与mef一起使用另一个ioc容器?

Wpf 如何与mef一起使用另一个ioc容器?,wpf,architecture,prism,mef,autofac,Wpf,Architecture,Prism,Mef,Autofac,我用的是带棱镜的mef。我可以使用mef,因为我喜欢导出、导入、元数据属性和主要的聚合cagalog使用。所以我想在prism项目中使用mef 在我的计划中,我的解决方案项目必须是使用autofac或castle windsor ioc容器,除prism项目(wpf)外,我的实现也是这样。在这种情况下,我不喜欢使用autofac或castle windsor代替mef的默认di/ioc,但太多个人体验的替代使用都失败了 是否有任何稳定的样本项目,我可以使用?我只想改变所有mef功能的mef io

我用的是带棱镜的mef。我可以使用mef,因为我喜欢导出、导入、元数据属性和主要的聚合cagalog使用。所以我想在prism项目中使用mef

在我的计划中,我的解决方案项目必须是使用autofac或castle windsor ioc容器,除prism项目(wpf)外,我的实现也是这样。在这种情况下,我不喜欢使用autofac或castle windsor代替mef的默认di/ioc,但太多个人体验的替代使用都失败了

是否有任何稳定的样本项目,我可以使用?我只想改变所有mef功能的mef ioc

我的经典mef引导程序代码如下 导入System.ComponentModel.Composition.Hosting 导入Microsoft.Practices.Prism.MefExtensions 导入Microsoft.Practices.ServiceLocation

Public Class Bootstrapper2
    Inherits MefBootstrapper

    Protected Overrides Sub ConfigureContainer()
        MyBase.ConfigureContainer()

        Dim ag As New AggregateCatalog()
        ag.Catalogs.Add(New AssemblyCatalog(GetType(Bootstrapper2).Assembly))
        ag.Catalogs.Add(New DirectoryCatalog("..\..\modules\", "Prism.Sample.Modules.*.dll"))

        Me.AggregateCatalog.Catalogs.Add(ag)
    End Sub


    Protected Overrides Function CreateShell() As DependencyObject
        Dim s As Shell = ServiceLocator.Current.GetInstance(Of Shell)()

        Return s
    End Function

    Protected Overrides Sub InitializeShell()
        Application.Current.MainWindow = Shell()
        Application.Current.MainWindow.Show()
    End Sub

End Class
壳牌公司代码如下: 导入System.ComponentModel.Composition

<Export()> _
Public Class Shell

    Sub New()
        InitializeComponent()
    End Sub

    <Import(AllowRecomposition:=False)> _
    Public Property ViewModel() As ShellViewModel
        Get
            Return CType(Me.DataContext, ShellViewModel)
        End Get
        Set(value As ShellViewModel)
            Me.DataContext = value
        End Set
    End Property


End Class
然后我得到了太多的解析异常,例如: 异常消息: 尝试获取注册表项“”的RegionaDapterAppings类型的实例时发生激活错误

Prism或其他代码库试图从servicelocator解析IRegionAdapterMappings,但currentservice locator不知道这是什么。因为mef在CreateServiceLocator之前已准备好注册此类型((ConfigureContainer)

因此,我尝试添加mef的聚合目录,以便在autofac.Integration.mef项目中注册autofac容器,如下所示:

Private autofacBuilder As New Autofac.ContainerBuilder

Protected Overrides Sub ConfigureServiceLocator()
    autofacBuilder.RegisterComposablePartCatalog(Me.AggregateCatalog)

    Dim autofacContainer = autofacBuilder.Build()
    Dim autofacSL = New Prism.AutofacExtension.AutofacServiceLocatorAdapter(autofacContainer)

    ServiceLocator.SetLocatorProvider(Function() autofacSL)
End Sub
然后我有一个不同的例外:IServiceLocator未注册等

我没有一个很好的解决方案来更改mef的ioc容器,因为它自己的容器类型和使用她自己的扩展性。尝试使用Autofac.Integration.mef,但可能它将来不兼容。可能在mef发布新版本时无法开发

我想我是个大洞。有什么办法我看不见吗


谢谢。

您能否将您的问题重新表述得更好一点,并提供一些说明代码?我尝试过AutofacBootstrapper,它可以工作,但我不想使用它们,因为我不确定将来是否支持所有mef功能。
Private autofacBuilder As New Autofac.ContainerBuilder

Protected Overrides Sub ConfigureServiceLocator()
    autofacBuilder.RegisterComposablePartCatalog(Me.AggregateCatalog)

    Dim autofacContainer = autofacBuilder.Build()
    Dim autofacSL = New Prism.AutofacExtension.AutofacServiceLocatorAdapter(autofacContainer)

    ServiceLocator.SetLocatorProvider(Function() autofacSL)
End Sub