【问题标题】:Inject mock service into Caliburn Micro at design time在设计时将模拟服务注入 Caliburn Micro
【发布时间】:2014-09-05 08:05:16
【问题描述】:

使用 Caliburn.Micro 2.0.1,我编辑了 AppBootStrapper.cs 以注入我的服务并且它正在工作,但我想知道是否有一种方法可以像你一样在设计时自动注入我的服务的模拟版本可以用 MVVM Light 吗?

例如

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

【问题讨论】:

    标签: c# mvvm caliburn.micro


    【解决方案1】:

    好的,感谢 StackOverflow 上的另一篇帖子 here(多么尴尬)。

    解决方案是使用“Execute.InDesignMode”

    例如

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

    【讨论】:

      猜你喜欢
      • 2013-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-24
      • 2013-04-27
      • 1970-01-01
      • 2021-08-30
      • 1970-01-01
      相关资源
      最近更新 更多