title: ASP.NET using AutoMapper
body: <p>I am learning ASP.NET by examples from the book on C# and that book was written at time when AutoMapper supported the method Initialize. I tried to circumvent it but not successfully. I replaced :</p>
  <pre><code>//    Mapper.Initialize(
    //    cfg =&gt;
    //    {
    //      cfg.CreateMap&lt;Inventory, Inventory&gt;()
    //.ForMember(x =&gt; x.Orders, opt =&gt; opt.Ignore());
    //    });
  </code></pre>
  <p>with:</p>
  <pre><code>var config = new MapperConfiguration(cfg =&gt; cfg.CreateMap&lt;Inventory, Inventory&gt;()
         .ForMember(x =&gt; x.Orders, opt =&gt; opt.Ignore()));
  </code></pre>
  <p>and it seems (at least do not show errors in VS 2019).</p>
  <p>But in the following:</p>
  <pre><code>// GET: api/Inventory
  [HttpGet, Route(&quot;&quot;)]
  public IEnumerable&lt;Inventory&gt; GetInventory()
  {
      var inventories = _repo.GetAll();
      return Mapper.Map&lt;List&lt;Inventory&gt;, List&lt;Inventory&gt;&gt;(inventories);
  }
  </code></pre>
  <p>I get an error:</p>
  <blockquote>
  <p>An object reference is required for the non-static field, method, or property 'Mapper.Map&lt;Inventory, Inventory&gt;(Inventory)</p>
  </blockquote>
  <p>Can somebody help me? Thanks. I am a newcomer here. Jiri</p>