How to use mapper.Map inside MapperConfiguration of AutoMapper?
<p>I need to map an object to another one using AutoMapper. The tricky question is how can I access an instance of the mapper (instance of IMapper) inside of the mapping configuration or inside of a custom type converter?</p>

<p>The code below does not work, however it is an example of what I would like to achieve - please notice the <code>mapper.Map</code> calls and assume that mappings <code>Customer =&gt; CustomerDto</code> and <code>Customer =&gt; DetailedCustomerDto</code> are defined.</p>

<pre><code>var config = new MapperConfiguration(
    cfg =&gt; cfg.CreateMap&lt;Order, OrderDto&gt;()
        .ForMember(dst =&gt; dst.Customer, src =&gt; src.ResolveUsing(o =&gt; {
            return o.Type == 1
                ? mapper.Map&lt;Customer, CustomerDto&gt;(o.Customer)
                : mapper.Map&lt;Customer, DetailedCustomerDto&gt;(o.Customer)
            })
    );
</code></pre>

<p>The client part is:</p>

<pre><code>var mapper = config.CreateMapper();
var orderDto = mapper.Map&lt;Order, OrderDto&gt;(order);
</code></pre>

<p>The simplified version of objects I want to map is:</p>

<pre><code>public class Order
{
    public int Type { get; set; }
    public Customer Customer { get; set; }
}

public class Customer
{
    public long Id { get; set; }
    public string Name { get; set; }
}

public class OrderDto
{
    public CustomerDto Customer { get; set; }
}

public class CustomerDto
{
    public long Id { get; set; }
}

public class DetailedCustomerDto : CustomerDto
{
    public string Name { get; set; }
}
</code></pre>

<p>As you see from the codes above, based on the value of <code>Order.Type</code>, the mapper should map the property <code>Order.Customer</code> to different targets. As one target (<code>DetailedCustomerDto</code>) inherits from the other one (<code>CustomerDto</code>) it becomes a bit tricky.</p>

<p><strong>Please notice that usage of the obsolete and deprecated static method Mapper.Map is NOT an option</strong>.</p>