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

How to Register Multiple Interface Implementation In IoC in MvvmLight?

如何使用MvvmLight的Ioc解决问题? 我有多个数据服务(DataService1、DataService2、DataService3 ...)。它们都是IDataService,需要和多个ViewModel联系。 Mvvmlight做不到:

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

您还可以在 MvvmLight 中使用 'class' 键标识符,就像这样

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");