title: How to build AutoMapper mapping to pass parameter in destination class constructor
body: <p>What if I have this set of source classes:</p>
  
  <pre><code>namespace Source {
  
      class CA
      {
          public CB B { get; set; }
      }
  
      class CB {}
  
  }
  </code></pre>
  
  <p>The only difference in destination set of classes is that CB accepts CA reference in constructor (CA is of the same structure):</p>
  
  <pre><code>namespace Destination {
  
      class CA
      {
         public CB B { get; set; }
      }
  
      class CB
      {
         public CB(CA parent) { ... }
      }
  }
  </code></pre>
  
  <p>How can I build a static mapping with AutoMapper for such classes? I mean something that runs once for whole application, not per CA, CB instances. </p>
  
  <p>I know I can do it dynamically like this before every mapping having instance of CA destination:</p>
  
  <pre><code>var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
  
  config.CreateMap&lt;Source.CB, Destination.CB&gt;()
          .ConstructUsing((ResolutionContext cntx) =&gt; 
              new Destination.CB(instanceOfCADestination));
  </code></pre>
  
  <p>but this does not work for me due to performance concerns.</p>