2017-07-09 81 views
0

Register Multiple Interface Implementation In LightInject IoC如何在MvvmLight中的IoC中注册多个接口实现?

如何使用MvvmLight的IOC来解决这个问题? 我有多个DataService(DataService1,DataService2,DataService3 ...)。它们都是IDataService,需要与多个ViewModel联系。 Mvvmlight不能做到这一点:

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

回答

0

您也可以使用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"); 
相关问题