1

我正在使用 AutoMapper 2.2.0 开发 ASP.NET MVC 3 应用程序。我声明了一些 AutoMapper 配置文件,当我手动初始化它们时,一切正常。

AutoMapper.Mapper.Initialize(x =>
{
    x.AddProfile<ProdutoToProdutoViewModel>();                    
    x.AddProfile<IPagedListProdutoToIPagedListProdutoViewModel>();
    x.AddProfile<ItemToItemViewModel>();
    x.AddProfile<CarrinhoToCarrinhoViewModel>();
});
//This is working

但是当我尝试使用 Bootstrapper.AutoMapper 2.0.3.0 初始化它们时......

Bootstrapper.With.AutoMapper().Start();

...抛出配置异常:

The following property on eGuruShop.Web.ViewModels.ItemViewModel cannot be mapped:
Itens
Add a custom mapping expression, ignore, add a custom resolver, or modify the destination type eGuruShop.Web.ViewModels.ItemViewModel.
Context:
Mapping to property Itens from eGuruShop.Domain.CatalogoProdutos.Item to eGuruShop.Web.ViewModels.ItemViewModel
Mapping to property Itens from System.Collections.Generic.IList`1[[eGuruShop.Domain.CatalogoProdutos.Item, eGuruShop.Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] to System.Collections.Generic.IList`1[[eGuruShop.Web.ViewModels.ItemViewModel, eGuruShop.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]
Mapping from type eGuruShop.Domain.CatalogoProdutos.Carrinho to eGuruShop.Web.ViewModels.CarrinhoViewModel
Exception of type 'AutoMapper.AutoMapperConfigurationException' was thrown

配置CarrinhoToCarrinhoViewModel文件取决于ItemToItemViewModel配置文件,当我将初始化顺序更改为

AutoMapper.Mapper.Initialize(x =>
{
    x.AddProfile<ProdutoToProdutoViewModel>();                    
    x.AddProfile<IPagedListProdutoToIPagedListProdutoViewModel>();
    x.AddProfile<CarrinhoToCarrinhoViewModel>();
    x.AddProfile<ItemToItemViewModel>();
});
//Exception

我有和以前一样的例外。

我怀疑 Bootstrapper 以错误的顺序初始化配置文件,但我不知道如何在不放弃 Bootstrapper 的情况下解决它。对这个问题有什么建议或解决方案吗?

谢谢

4

0 回答 0