2014-09-05 55 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()); 
相关问题