2012-11-24 56 views
0

我從Caliburn.Micro.Bootstrapper派生了一個自定義引導程序,我注意到它可以使用一個泛型類型參數 - 這是幹什麼用的?來自Caliburn.Micro.Bootstrapper的自定義引導程序,什麼是引導程序<IContract>?

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); 
    } 
} 

回答

1

這是一個視圖模型類型用作您的起始視圖模型。 Caliburn.Micro將從IoC容器中解析該類型,並在WPF中使用WindowManager來顯示根視圖。 Bascially您在覆蓋OnStartup時正在做什麼。

相關問題