2013-01-22 105 views
2

能我稱棱鏡模塊中的每個Initialize方法來配置的地圖爲在不同的模塊的對象Mapper.CreateMap?我喜歡這種方法,這樣的模塊和映射可需單獨開發WPF PRISM模塊和AutoMapper

或者我應該叫在一箇中心位置的Mapper.CreateMap這可能是在引導程序?它在引導程序中,MEFbootstrapper的重寫方法最好?

回答

0

我知道這個問題是很老了,但我想知道同樣的事情,我碰到你的問題就來了。在當前事物的狀態(棱鏡5 & AutoMapper 3.2.1),你可以在每個棱鏡模塊的模塊定義創建映射。

public void Initialize() 
    { 
     this.RegisterViewsAndServices(); 
     this.ResolveAutomapping(); 
    } 

private void ResolveAutomapping() 
    { 
     AutoMapper.Mapper.CreateMap<Entities.Channel, Modules.EntityWrappers.ChannelWrapper>().ForMember("Selected", o => o.UseValue(false)); 
    } 

在我的ViewModel然後,我沒有問題

Channels = new ObservableCollection<ChannelWrapper>(data.Select(r => AutoMapper.Mapper.Map<ChannelWrapper>(r))); 
調用此