我的第一个问题是,我无法在其他地方找到确切的答案。
使用Automapper 4.2.1,Unity 4.01
我试图让Automapper配置文件再次调用我的服务接口来获取嵌套对象以映射到我的目标属性。最终我宁愿不使用ResolveUsing,但如果这对我来说没问题。
public class HeadlineMap : Profile
{
private readonly IDeserializeModels _deserialize;
public HeadlineMap(IDeserializeModels argDeserializeModels)
{
_deserialize = argDeserializeModels;
}
protected override void Configure()
{
CreateMap<LiveSiteHeadline, Headline>().
...
ForMember(t => t.VideoTitle, options => options.MapFrom(f => f.videoTitle)).
ForMember(t => t.Disclaimer, options => options.ResolveUsing<ResolveDisclaimerReference>().ConstructedBy(()=> new ResolveDisclaimerReference(_deserialize)));
}
}
public class ResolveDisclaimerReference : ValueResolver<LiveSiteHeadline, Object>
{
private readonly IDeserializeModels _deserialize;
public ResolveDisclaimerReference(IDeserializeModels argDeserializeModels)
{
_deserialize = argDeserializeModels;
}
protected override object ResolveCore(LiveSiteHeadline source)
{
return _deserialize.GetResponseObject(source.disclaimer.urlPattern, source.disclaimer.project, source.disclaimer.path);
}
}
我使用推荐的4.2.1方式在Unity容器中注册我的所有地图:
var config = new MapperConfiguration(cfg =>
{
foreach (var profile in profiles)
{
cfg.AddProfile(profile);
}
});
container.RegisterType<MapperConfiguration>(new ContainerControlledLifetimeManager(),
new InjectionFactory(c => config))
.RegisterType<IMapper>(new InjectionFactory(c => c.Resolve<MapperConfiguration>().CreateMapper()));
但是当我运行上述内容时,我得到了 -
&#34;缺少类型映射配置或不支持的映射。&#34;。
关于我失踪的任何想法?使用ObjectFactory的其他示例,Ninject似乎不起作用,因为我不能使用它们。