title: Automapper error saying mapper not initialized
body: <p>I am using Automapper 5.2. I have used as a basis <a href="https://stackoverflow.com/questions/41220742/setting-up-automapper-5-1">this</a> link. I will describe, in steps, the process of setting up Automapper that I went through.</p>
  
  <p><strong>First</strong> I added Automapper to Project.json as indicated:</p>
  
  <pre><code>PM&gt; Install-Package AutoMapper
  </code></pre>
  
  <p><strong>Second</strong> I created a folder to hold all files relating to mapping called "Mappings"</p>
  
  <p><strong>Third</strong> I set up the configuration of Automapper in its own file in the mappings folder :</p>
  
  <pre><code>public class AutoMapperConfiguration
  {
      public MapperConfiguration Configure()
      {
          var config = new MapperConfiguration(cfg =&gt;
          {
              cfg.AddProfile&lt;ViewModelToDomainMappingProfile&gt;();
              cfg.AddProfile&lt;DomainToViewModelMappingProfile&gt;();
              cfg.AddProfile&lt;BiDirectionalViewModelDomain&gt;();
          });
          return config;
      }
  }
  </code></pre>
  
  <p><strong>Forth</strong> Also in its own file in the mappings folder I set up the mapping profile as follows:</p>
  
  <pre><code>public class DomainToViewModelMappingProfile : Profile
  {
      public DomainToViewModelMappingProfile()
      {
          CreateMap&lt;Client, ClientViewModel&gt;()
             .ForMember(vm =&gt; vm.Creator, map =&gt; map.MapFrom(s =&gt; s.Creator.Username))
             .ForMember(vm =&gt; vm.Jobs, map =&gt; map.MapFrom(s =&gt; s.Jobs.Select(a =&gt; a.ClientId)));
      }
  }
  </code></pre>
  
  <p><strong>Fifth</strong>, I added an extension method as its own file also in the mappings folder... this was used next in startup.cs:</p>
  
  <pre><code>public static class CustomMvcServiceCollectionExtensions
  {
      public static void AddAutoMapper(this IServiceCollection services)
      {
          if (services == null)
          {
              throw new ArgumentNullException(nameof(services));
          }
          var config = new AutoMapperConfiguration().Configure();
          services.AddSingleton&lt;IMapper&gt;(sp =&gt; config.CreateMapper());
      }
  }
  </code></pre>
  
  <p><strong>Sixth</strong> I added this line into the ConfigureServices method in Startup.cs</p>
  
  <pre><code>        // Automapper Configuration
          services.AddAutoMapper();
  </code></pre>
  
  <p>Finally I used it in a controller to convert a collection...</p>
  
  <pre><code> IEnumerable&lt;ClientViewModel&gt; _clientVM = Mapper.Map&lt;IEnumerable&lt;Client&gt;, IEnumerable&lt;ClientViewModel&gt;&gt;(_clients);
  </code></pre>
  
  <p>Based on the question I referred to earlier I thought I had everything set so I could use it however I got an error on the line above in the Controller...</p>
  
  <blockquote>
    <p>"Mapper not initialized. Call Initialize with appropriate configuration. If you are trying to use mapper instances through a container or otherwise, make sure you do not have any calls to the static Mapper.Map methods, and if you're using ProjectTo or UseAsDataSource extension methods, make sure you pass in the appropriate IConfigurationProvider instance."</p>
  </blockquote>
  
  <p>What have I missed.. Is this the correct way to set up Automapper? I suspect I am missing a step here.. any help greatly appreciated.</p>