How to use AfterMap to map properties on collection property
<p>I have two entities and two DTOs. I am mapping the entities to the DTOs. Simplified versions of the DTOs look like:</p>

<pre><code>public class FooDto {
     // Other properties removed for clarity.
     public string Description { get; set; }
     public decimal Total { get; set; }
     public ICollection&lt;BarDto&gt; Bars { get; set; }
}

public class BarDto {
     // Other properties removed for clarity.
     public decimal Total { get; set; }
}
</code></pre>

<p>The <code>Foo</code> and <code>Bar</code> classes are:</p>

<pre><code>public class Foo {

     public ICollection&lt;Bar&gt; Bars { get; set; }
}

public class Bar {
    // Unimportant properties
}
</code></pre>

<p><strong><em>The Mapping</em></strong></p>

<p>I am mapping this in a method as:</p>

<pre><code>public FooDto Map(IMapper mapper, Foo foo) {

        // _fooTotalService and _barTotalService injected elsewhere by DI.

        return mapper.Map&lt;Foo, FooDto&gt;(foo, opt =&gt;
        {
            opt.AfterMap((src, dest) =&gt;
            {
                dest.Total = _fooTotalService.GetTotal(src);
                dest.Bars.Total = ?????? // Needs to use _barTotalService.CalculateTotal(bar)
            });
        });
}
</code></pre>

<p>AutoMapper already has mappings configured for Foo to FooDto and Bar to BarDto which are working fine. </p>

<p>I need to update each BarDto in FooDto with a total using a service (the reasons for which are too lengthy to go into - suffice to say it needs to happen this way).</p>

<p>What syntax do I need to use in <code>AfterMap</code> to map each <code>Total</code> property of <code>BarDto</code> using the <code>_barTotalService.CalculateTotal(bar)</code> method, where <code>bar</code> is the <code>Bar</code> in question?  </p>

<p>Note that the <code>_barTotalService.CalculateTotal</code> method takes an instance of <code>Bar</code> not <code>BarDto</code>.</p>