Csharp/C#教程:如果接口位于不同的程序集中,则SimpleIoc.Default.Register在IsInDesignModeStatic处失败分享


如果接口位于不同的程序集中,则SimpleIoc.Default.Register在IsInDesignModeStatic处失败

ViewModelLocator类的静态构造函数中, SimpleIoc.Default.Register(); 如果接口位于不同的项目中,则在IsInDesignModeStatic模式下失败。 因此, MainWindow.xaml设计器在设计时是空的。

我已经做了一个简单的解决方案来测试它。 我所做的只是将DataItem类和IDataService接口移动到Domain项目中。

在这里下载

我找到了一个随处:在ClientWpf项目中添加指向IDataService.cs的链接。

上述就是C#学习教程:如果接口位于不同的程序集中,则SimpleIoc.Default.Register在IsInDesignModeStatic处失败分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!

 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(); } else { SimpleIoc.Default.Register(); } SimpleIoc.Default.Register(); } ... } 

  if (ViewModelBase.IsInDesignModeStatic) { // put these lines here: if (SimpleIoc.Default.IsRegistered()) { SimpleIoc.Default.Unregister(); } SimpleIoc.Default.Register(); } else { SimpleIoc.Default.Register(); } 

本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

ctvol管理联系方式QQ:251552304

本文章地址:https://www.ctvol.com/cdevelopment/1016814.html

(0)
上一篇 2021年12月31日
下一篇 2021年12月31日

精彩推荐