0

在 LightInject IoC 中注册多接口实现

如何使用 MvvmLight 的 Ioc 解决问题?我有多个 DataService(DataService1、DataService2、DataService3 ...)。它们都是IDataService,需要与多个ViewModel联系。mvvmlight 做不到:</p>

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

1 回答 1

1

您还可以在 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");
于 2017-07-12T08:57:44.770 回答