2014-09-05 56 views
0

使用Caliburn.Micro 2.0.1,我編輯了AppBootStrapper.cs以注入我的服務並且它正在工作,但我想知道是否有辦法自動注入模擬在設計期間我可以使用MVVM Light的服務版本嗎?在設計時向Caliburn Micro注入模擬服務

E.g.

protected override void Configure() 
    { 
     _container = new SimpleContainer(); 
     _container.PerRequest<MainViewModel>(); 
     _container.Instance<IWindowManager>(new WindowManager()); 
     _container.Singleton<IEventAggregator, EventAggregator>(); 

     // like this... 
     if (IsInDesignMode) 
     { 
      _container.Instance<IMyService>(new MyServiceMock()); 
     } 
     else 
     { 
      _container.Instance<IMyService>(new MyService()); 
     } 
    } 

回答

1

好吧,所以我想通了,謝謝StackOverflow here(多麼尷尬)的另一篇文章。

解決方案是使用「Execute.InDesignMode」

E.g.

if (Execute.InDesignMode) 
      _container.Instance<IMyService>(new MyServiceMock()); 
     else 
      _container.Instance<IMyService>(new MyService()); 
相關問題