我一直在尝试使用AutoMapper通过Ninject实例化所有对象。
我在global.asax文件中添加了以下代码:
Mapper.Configuration.ConstructServicesUsing(x => kernel.Get(x));
作为一个例子,我有以下映射。
Mapper.CreateMap<TestModel, IndexViewModel>();
然而,这似乎并没有起作用。我收到一个错误,说“IndexViewModel”没有默认构造函数。
我可以通过显式告诉automapper在映射中使用ninject来使映射器工作。
Mapper.CreateMap<TestModel, IndexViewModel>().ConstructUsingServiceLocator();
但我不想为每个映射都这样做。我有什么遗漏吗?
IndexViewModel
?你能否通过显式的kernel.Get<IndexviewModel>()
调用来解决它? - Damian Powell