SimpleIoc.Default.Register kończy się niepowodzeniem w IsInDesignModeStatic, jeśli interfejs jest w innym złożeniu
W statycznym konstruktorzeViewModelLocator
klasaSimpleIoc.Default.Register<T>();
zawodzi wIsInDesignModeStatic
tryb, jeśli interfejs jest w innym projekcie. W rezultacieMainWindow.xaml
projektant jest pusty w czasie projektowania.
Zrobiłem proste rozwiązanie, aby to przetestować. Jedyne zmiany, które zrobiłem, to przesunięcieDataItem
klasa iIDataService
interfejs do projektu domeny.
Znalazłem spacer: Dodaj łącze do IDataService.cs w projekcie ClientWpf.
public class ViewModelLocator {
static ViewModelLocator() {
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic) {
// It fails if the IDataService is in different assembly
// Delete the link of IDataService.cs from the ViewModel folder...
SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
}
else {
SimpleIoc.Default.Register<IDataService, DataService>();
}
SimpleIoc.Default.Register<MainViewModel>();
}
...
}