根据作者在2.0版中的帖子
http://lostechies.com/jimmybogard/2011/09/29/automapper-2-0-nestedchild-containers/
但是这个测试不起作用,有人可以指出这里有什么不对吗?
要传递的测试,automapper必须调用ConstructServicesUsing中传递的代码,它不是
public class Source
{
public int SomeValue { get; set; }
}
public class Destination
{
public Destination() { }
public Destination(bool value)
{
this.WasCustom = true;
}
public bool WasCustom { get; private set; }
public int SomeValue { get; set; }
}
[TestMethod]
public void can_make_servicelocator_work()
{
Mapper.CreateMap<Source, Destination>();
var source = new Source { SomeValue = 100 };
var dest = Mapper.Map<Source, Destination>(source,
(option) => option.ConstructServicesUsing((t) => new Destination(true)));
Assert.IsTrue(dest.WasCustom);
}