title: AutoMapper nested mapping with DI
body: <p>Mapping of nested objects is pretty straightforward with AutoMapper as long as there is a Map definition for the nested objects as well. I am facing an issue with implementing a Map between 2 objects, one of which <strong>does not and cannot have a parameter-less constructor</strong>. Let's say the Order object is such as below. The services are injected by autofac constructor dependency injection.</p>
  
  <pre><code>public class Order
  {
      private readonly IOrderDetailsService _orderDetailsService;
  
      public Order(IOrderDetailsService orderDetailsService)
      {
          _orderDetailsService = orderDetailsService;
      }
  
      public string Name { get; set; }
      public int Id { get; set; }
  
      [NonSerialized] private IEnumerable&lt;OrderDetails&gt; _details;
  
      public IEnumerable&lt;OrderDetails&gt; Details
      {
          get
          {
              _details = _orderDetailsService.GetDetailsByOrderId(Id);
              return _details;
          }
          set { _details = value; }
      }
  
  }
  
  public class OrderDetails
  {
      private readonly IOrderService _orderService;
      public OrderDetails(IOrderService orderService)
      {
          _orderService = orderService;
      }
  
      public int OrderId { get; set; }
      public int DetailId { get; set; }
      public string DetailInfo { get; set; }
  
      public Order Order
      {
          get { return _orderService.GetOrderById(OrderId); }
      }
  }
  </code></pre>
  
  <p>And if there was a View Model such as below:</p>
  
  <pre><code>public class OrderViewModel
  {
      public string OrderName { get; set; }
      public int OrderId { get; set; }
      public IEnumerable&lt;OrderDetailsViewModel&gt; Details { get; set; } 
  }
  
  public class OrderDetailsViewModel
  {
      public int DetailId { get; set; }
      public string DetailInformation { get; set; }
  }
  </code></pre>
  
  <p>How would we go about Mapping Order to OrderViewModel and vice versa?</p>