I'm working on an ASP.NET MVC 3 application using AutoMapper 2.2.0. I have some AutoMapper profiles declared and when I initialize them manually everything works just fine.
AutoMapper.Mapper.Initialize(x =>
{
x.AddProfile<ProdutoToProdutoViewModel>();
x.AddProfile<IPagedListProdutoToIPagedListProdutoViewModel>();
x.AddProfile<ItemToItemViewModel>();
x.AddProfile<CarrinhoToCarrinhoViewModel>();
});
//This is working
But when I try to initialize them with Bootstrapper.AutoMapper 2.0.3.0...
Bootstrapper.With.AutoMapper().Start();
...a configuration exception is thrown:
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
The CarrinhoToCarrinhoViewModel
profile depends on the ItemToItemViewModel
profile and when I change the initialization order to
AutoMapper.Mapper.Initialize(x =>
{
x.AddProfile<ProdutoToProdutoViewModel>();
x.AddProfile<IPagedListProdutoToIPagedListProdutoViewModel>();
x.AddProfile<CarrinhoToCarrinhoViewModel>();
x.AddProfile<ItemToItemViewModel>();
});
//Exception
I've got the same exception than before.
I suspect Bootstrapper is initializing the profiles in the wrong order, but I don't know how to solve it without abandoning Bootstrapper. Any suggestions or solutions to this problem?
Thanks