Wpf Caliburn.Micro+;Autofac自举

Wpf Caliburn.Micro+;Autofac自举,wpf,mvvm,dependency-injection,autofac,caliburn.micro,Wpf,Mvvm,Dependency Injection,Autofac,Caliburn.micro,我和Caliburn.Micro有一个项目,我正在尝试从它的 我正在使用,这是中代码的更新版本。 使用SimpleContainer我只是做了(在引导程序内部) 启动时受保护的覆盖无效(对象发送方,System.Windows.StartupEventArgs e) { this.DisplayRootViewFor();//其中ShellViewModel:Screen } 现在这已经不起作用了,那么我应该怎么做才能将Autofac与Caliburn.Micro集成呢?您的解决方案存在一些问

我和Caliburn.Micro有一个项目,我正在尝试从它的

我正在使用,这是中代码的更新版本。 使用
SimpleContainer
我只是做了(在引导程序内部)

启动时受保护的覆盖无效(对象发送方,System.Windows.StartupEventArgs e)
{
this.DisplayRootViewFor();//其中ShellViewModel:Screen
}

现在这已经不起作用了,那么我应该怎么做才能将Autofac与Caliburn.Micro集成呢?

您的解决方案存在一些问题

首先,没有任何东西调用您的
AppBootstrapper
。这通常在Caliburn.Micro中通过在
App.xaml
中添加引导程序类型作为资源来完成。有关WPF的说明,请参阅

i、 e.您的
App.xaml
应该如下所示:

<Application x:Class="AutofacTests.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:local="clr-namespace:AutofacTests">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:AppBootstrapper x:Key="bootstrapper" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>

发生了什么,你是遇到了异常还是什么?请提供更多细节。谢谢,没什么。我注意到的一件奇怪的事情是,它甚至没有启动OnStartup方法。理论上,DisplayRootViewFor应该为ShellView和ShellViewModel调用WindowManager.ShowDialog,但没有显示任何内容。您是否在未经修改的情况下使用按原样发布的链接中的引导程序?是的,来自github的引导程序。我只是添加了onstartup覆盖,就像我在使用SimpleContainer时所做的一样。我所做的另一件事是创建一个普通的公共类AppBootstrapper:AutofacBootstrapper{},在App.cs中我只做var boot=new AppBootstrapper();boot.Start();正如我所写的,正如您在所附的解决方案中所看到的,我创建了一个新的引导程序,并在app.cs中对其调用start,无论如何,现在我将尝试您的建议。我覆盖了SelectAssemblys方法,但没有任何更改,您能看一下我的解决方案并告诉我它需要的确切编辑吗?谢谢你这些正是你需要的改变,我自己为你的解决方案做的。您是否对App.xaml进行了更改?你的SelectAssemblys在AppBootstrapper中吗?现在我创建了另一个项目,将bootstrapper、view和viewmodel都放在同一个程序集中,我现在可以工作了。我将尝试将它们分开,让我们看看我可以工作了!我不明白为什么,但我仍然在App.xaml引导程序资源定义上遇到一个奇怪的错误,说它找不到System.Core 2.0.5.0版,但除此之外,它还能工作!谢谢你们!
<Application x:Class="AutofacTests.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         xmlns:local="clr-namespace:AutofacTests">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <local:AppBootstrapper x:Key="bootstrapper" />
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </Application.Resources>
</Application>
protected override IEnumerable<Assembly> SelectAssemblies()
{
    return new[]
               {
                   GetType().Assembly, 
                   typeof(ShellViewModel).Assembly, 
                   typeof(ShellView).Assembly
               };
}