0

Using Caliburn.Micro 2.0.1, I've edited AppBootStrapper.cs to inject a service of mine and it's working, but I was wondering if there's a way to automatically inject a mock version of my service during design time like you can with MVVM Light?

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());
        }
    }
Michael
  • 600
  • 6
  • 15

1 Answers1

1

Ok so I figured it out thanks to another post on StackOverflow here (how embarrassing).

The solution was to use "Execute.InDesignMode"

E.g.

if (Execute.InDesignMode)
            _container.Instance<IMyService>(new MyServiceMock());
        else
            _container.Instance<IMyService>(new MyService());
Community
  • 1
  • 1
Michael
  • 600
  • 6
  • 15