我从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);
}
}
答案 0 :(得分:1)
它是用作起始视图模型的视图模型类型。 Caliburn.Micro将从IoC容器中解析类型,并在WPF中使用WindowManager
来显示根视图。基本上你在OnStartup
覆盖中正在做什么。