title: Inject parameter into automapper custom ValueResolver using Ninject
body: <p>I'm using <code>automapper</code> library to convert my <code>Model</code> into my <code>ViewModel</code>. For each <code>Model</code>, I create profile which inside i add my maps using <code>CreateMap</code>.</p>
  
  <p>I want to use custom <code>ValueResolver</code> in which it will get the logged user ID from <code>IContext</code>, so i need to pass implementation of <code>IContext</code> using Ninject.</p>
  
  <p>Inside my profile class:</p>
  
  <pre><code>Mapper.CreateMap&lt;ViewModel, BusinessModel&gt;()
  .ForMember(dest =&gt; dest.ManagerId, opt =&gt; opt.ResolveUsing&lt;GetManagerResolver&gt;());
  </code></pre>
  
  <p>Then my <code>GetManagerResolver</code>:</p>
  
  <pre><code>public class GetManagerResolver : ValueResolver&lt;BusinessModel, int&gt;
  {
      private IContext context;
      public GetManagerResolver(IContext context)
      {
          this.context = context;
      }
  
      protected override int GetManagerResolver(BusinessModel source)
      {
          return context.UserId;
      }
  }
  </code></pre>
  
  <p>But i get this exception message <code>{"Type needs to have a constructor with 0 args or only optional args\r\nParameter name: type"}</code>. </p>
  
  <p>Any Ideas on how make automapper use ninject for object creation?</p>
  
  <p><strong>UPDATE</strong>
  My code to add automapper configuration:</p>
  
  <pre><code>public static class AutoMapperWebConfiguration
  {
      public static void Configure()
      {
          Mapper.Initialize(cfg =&gt;
          {            
              cfg.AddProfile(new Profile1());         
              cfg.AddProfile(new Profile2());
  
              // now i want to add this line, but how to get access to kernel in static class?
              // cfg.ConstructServicesUsing(t =&gt; Kernel.Get(t));
          });
      }
  }
  </code></pre>