0

我从 Caliburn.Micro.Bootstrapper 派生了一个自定义引导程序,我注意到它可以采用泛型类型参数 - 这是为了什么?

public class SimpleInjectorBootstrapper : Caliburn.Micro.Bootstrapper
{
    private Container container;

    public SimpleInjectorBootstrapper()
    {
    }

    protected override void Configure()
    {
        this.container = new Container();
        this.container.Register<IWindowManager, WindowManager>();
        this.container.Register<IEventAggregator, EventAggregator>();
        this.container.Register<IAppViewModel, AppViewModel>();
    }

    protected override object GetInstance(Type serviceType, string key)
    {
        return this.container.GetInstance(serviceType);
    }

    protected override IEnumerable<object> GetAllInstances(Type serviceType)
    {
        return this.container.GetAllInstances(serviceType);
    }

    protected override void OnStartup(object sender, System.Windows.StartupEventArgs e)
    {
        base.OnStartup(sender, e);
        var appViewModel = this.container.GetInstance<IAppViewModel>();
        var windowManager = this.container.GetInstance<IWindowManager>();
        windowManager.ShowWindow(appViewModel);
    }
}
4

1 回答 1

1

它是一种用作起始视图模型的视图模型类型。Caliburn.Micro 将从 IoC 容器中解析类型,并在 WPF 中使用WindowManager来显示根视图。基本上你在OnStartup覆盖中所做的事情。

于 2012-11-24T20:06:09.827 回答