如何在MvvmLight中注册IoC中的多接口实现?
如何使用MvvmLight的Ioc来解决这个问题? 我有多个DataService(DataService1、DataService2、DataService3…)。它们都是IDataService,需要与多个ViewModel联系。 Mvvmlight无法执行此操作:如何在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
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”);