带有嵌套子容器的自动apper

本文关键字:apper 嵌套 | 更新日期: 2023-09-27 18:14:08

根据作者在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);
    }

带有嵌套子容器的自动apper

我在automapper论坛上问了同样的问题,根据作者的说法,这将在2.1

中可用。

这里是链接