我安装在我的 .NET 项目中:
- MvvmLight v5.4.1.1
- 城堡.温莎 v5.0.0
- CommonServiceLocator v2.0.2
- CommonServiceLocator.WindsorAdapter.Unofficial v3.3.0
然后我像这样初始化我的容器
public ViewModelLocator()
{
var container = new WindsorContainer();
ServiceLocator.SetLocatorProvider(() => new WindsorServiceLocator(container));
container.Register(Component.For<MainViewModel>().ImplementedBy<MainViewModel>());
}
这给出了这个错误:
'ServiceLocatorImplBase' 类型是在未引用的程序集中定义的。您必须添加对程序集“Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”的引用。
基本上,MvvmLight v5.4.1.1 期望 CommonServiceLocator v2.0.2,CommonServiceLocator.WindsorAdapter.Unofficial 期望 CommonServiceLocator v1.3.0,CommonServiceLocator.WindsorAdapter 期望 CommonServiceLocator v1.0.0
一种解决方案是将 CommonServiceLocator 降级到 v1.3.0 并且它可以工作,但随后 MvvmLight 也会降级到 v5.3.0
这样做的正确方法是什么?如何让 MvvmLight 和温莎城堡一起工作?