title: Configuring AutoMapper in ASP.NET Core
body: <p>I am trying to use automapper 8.0.0 to fill a list of <code>WorkViewModel</code>.
  This list is getting data from the <code>Work</code> class out of the database using entity framework.</p>
  
  <p>How ever it looks like something is going wrong with initializing as throwing follows error:</p>
  
  <blockquote>
    <p>InvalidOperationException: Mapper not initialized</p>
  </blockquote>
  
  <p>What am I doing wrong?</p>
  
  <p>I have setup the following code!</p>
  
  <p>Startup.cs </p>
  
  <pre><code>services.AddAutoMapper();
  </code></pre>
  
  <p>Function being called:</p>
  
  <pre><code>public async Task&lt;IEnumerable&lt;WorkViewModel&gt;&gt; GetAllAsync()
  {
      IList&lt;Work&gt; works = await _context.Work.ToListAsync();
  
      IList&lt;WorkViewModel&gt; viewModelList = Mapper.Map&lt;IList&lt;Work&gt;, IList&lt;WorkViewModel&gt;&gt;(works);
  
      return viewModelList;
  }
  </code></pre>
  
  <p>Configuration:</p>
  
  <pre><code>public class MappingProfile : Profile
  {
      public MappingProfile()
      {
          Mapper.Initialize(cfg =&gt;
          {
              cfg.CreateMap&lt;WorkViewModel, Work&gt;();
          });
      }
  }
  </code></pre>
  
  <p>WorkViewModel:</p>
  
  <pre><code>public class WorkViewModel
  {
      public int WorkID { get; set; }
      public string Name { get; set; }
      public byte[] Tumbmail { get; set; }
      public string Discription { get; set; }
  
      public string Client { get; set; }
      public DateTime Date { get; set; }
      public string PreviewLink { get; set; }
      public string GitLink { get; set; }
      public string DownloadLink { get; set; }
  
      public int DetailID { get; set; }
      public byte[] Banner { get; set; }
      public string Documentation { get; set; }
  
      public int CategoryID { get; set; }
      public string Category { get; set; }
  }
  </code></pre>
  
  <p>Work Model:</p>
  
  <pre><code>public class Work
  {
      [Key]
      public int WorkID { get; set; }
  
      [Display(Name = "Project Name")]
      public string Name { get; set; }
  
      [Display(Name = "Client name")]
      public string Client { get; set; }
  
      [Display(Name = "Description")]
      public string Discription { get; set; }
  
      [Display(Name = "Date")]
      public DateTime Date { get; set; }
  
      [Display(Name = "Thumbmail")]
      public byte[] Tumbmail { get; set; }
  
      [Display(Name = "Preview Link")]
      public string PreviewLink { get; set; }
  
      [Display(Name = "Git Link")]
      public string GitLink { get; set; }
  
      [Display(Name = "DownloadLink")]
      public string DownloadLink { get; set; }
  
  
      public WorkCategory workCategory { get; set; }
      public WorkDetailed WorkDetailed { get; set; }
  }
  </code></pre>