Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MvvmLight中注册IoC中的多接口实现?_Mvvm_Mvvm Light_Viewmodellocator - Fatal编程技术网

如何在MvvmLight中注册IoC中的多接口实现?

如何在MvvmLight中注册IoC中的多接口实现?,mvvm,mvvm-light,viewmodellocator,Mvvm,Mvvm Light,Viewmodellocator,如何使用MvvmLight的Ioc来解决这个问题? 我有多个DataService(DataService1、DataService2、DataService3…)。它们都是IDataService,需要与多个ViewModel联系。 Mvvmlight无法执行此操作: SimpleIoc.Default.Register<IDataService, DataService1>("DataService1Key"); SimpleIoc.Default.Register<IDa

如何使用MvvmLight的Ioc来解决这个问题? 我有多个DataService(DataService1、DataService2、DataService3…)。它们都是IDataService,需要与多个ViewModel联系。 Mvvmlight无法执行此操作:

SimpleIoc.Default.Register<IDataService, DataService1>("DataService1Key");
SimpleIoc.Default.Register<IDataService, DataService2>("DataService2Key");
...
simpleoc.Default.Register(“DataService1Key”);
SimpleIoc.Default.Register(“DataService2Key”);
...

您还可以在MvvmLight中使用“类”键标识符,如下所示

Class1 c1 = new Class1();
Class2 c2 = new Class2();

SimpleIoc.Default.Register<IDataClass>(() => c1, "Class1");
SimpleIoc.Default.Register<IDataClass>(() => c2, "Class2");

var t = SimpleIoc.Default.GetInstance<IDataClass>("Class1");
var s = SimpleIoc.Default.GetInstance<IDataClass>("Class2");
class1c1=newclass1();
Class2 c2=新的Class2();
simpleoc.Default.Register(()=>c1,“Class1”);
SimpleIoc.Default.Register(()=>c2,“Class2”);
var t=SimpleIoc.Default.GetInstance(“Class1”);
var s=SimpleIoc.Default.GetInstance(“Class2”);