这个问题看起来很幼稚,但我不理解ViewModelLocator.cs文件中的这段代码:
假设我有另一个DataService(例如DataService2),但这个我将与Page2ViewModel一起使用,我该怎么做呢?
另外,如果有人能帮助我(或甚至给我一个链接阅读)关于上述代码。我不知道它的含义。
static ViewModelLocator()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
if (ViewModelBase.IsInDesignModeStatic)
{
SimpleIoc.Default.Register<IDataService, Design.DesignDataService>();
}
else
{
SimpleIoc.Default.Register<IDataService, DataService>();
}
SimpleIoc.Default.Register<MainViewModel>();
}
我看到我们使用DataService获取数据(例如来自WCF服务),然后将其分配给MainViewModel。但是如果我要注册多个ViewModel怎么办?就像这样:
static ViewModelLocator()
{
....
SimpleIoc.Default.Register<MainViewModel>();
SimpleIoc.Default.Register<Page2ViewModel>();
}
假设我有另一个DataService(例如DataService2),但这个我将与Page2ViewModel一起使用,我该怎么做呢?
另外,如果有人能帮助我(或甚至给我一个链接阅读)关于上述代码。我不知道它的含义。