title: Automapper 9.0 dependency injection inplementation giving error
body: <p>I have just started to use Automapper and cannot seem to get the configuration correct. There are a number of conflicting explanations on SO and the documentation is not that clear at least for me.</p>
  
  <p>At the moment I am getting the following error.</p>
  
  <pre><code>Unable to resolve service for type 'AutoMapper.MapperConfiguration' while attempting to activate 'JobsLedger.API.Controllers.API.App.ODataClientController
  </code></pre>
  
  <p>In Startup.cs I have the following:</p>
  
  <pre><code>services.AddAutoMapper(c =&gt; c.AddProfile&lt;AutoMapping&gt;(), typeof(Startup));
  </code></pre>
  
  <p>My profile has been set up as follows:</p>
  
  <pre><code>public class AutoMapping : Profile
  {
      public AutoMapping()
      {
          // Add as many of these lines as you need to map your objects
          CreateMap&lt;Client, ClientIndexDto&gt;();
          //CreateMap&lt;UserDto, User&gt;();
      }
  }
  </code></pre>
  
  <p>and in my controller I have the following:</p>
  
  <pre><code>    public class ODataClientController : ODataController, IClientController {
      private readonly MapperConfiguration _mapper;
      private IClientDATARepository _clientDATARepository;
      private readonly IClientServices _clientServices;
      private readonly DATAContext _context;
  
      public ODataClientController(MapperConfiguration mapper, IClientDATARepository clientDATARepository, IClientServices clientServices, DATAContext context) {
          _mapper = mapper;
          _clientDATARepository = clientDATARepository;
          _clientServices = clientServices;
          _context = context;
      }
  
  
      [HttpGet]
      [ODataRoute("AllClients()")]
      [EnableQuery()]
      public IQueryable&lt;ClientIndexDto&gt; Get(ODataQueryOptions&lt;ClientIndexDto&gt; options) 
      {
          var clients = _clientDATARepository.AllIncluding();
          var clientIndexDtos = clients.ProjectTo&lt;ClientIndexDto&gt;(_mapper);  // magic happens here...
  
          return (IQueryable&lt;ClientIndexDto&gt;)options.ApplyTo(clientIndexDtos);
      }
  </code></pre>
  
  <p>I have installed NuGet packages for Automapper - 9.0.0 and Automapper extensions for dependency injection 7.0.0</p>
  
  <p>This is all I have done to get this up and running. What am I missing or what is wrong with this implementation.</p>
  
  <p>I used <a href="https://www.codementor.io/@zedotech/how-to-using-automapper-on-asp-net-core-3-0-via-dependencyinjection-zq497lzsq" rel="nofollow noreferrer">this</a> from the Code Mentor Community website and I have used <a href="https://stackoverflow.com/a/54760018/5750758">this answer</a> from SO to set up the projection.</p>
  
  <p><strong>UPDATE</strong> - Thank you for identifying a typo.. as I mentioned there are a number of variations of implementations as well as a number of implementations relating to versions some of which are out of date. Its difficult when you are new to this package to get an idea of what is a single source of truth. That being said I have changed that MapperConfiguration keyword to IMapper as follows:</p>
  
  <pre><code>    public class ODataClientController : ODataController, IClientController {
      private readonly IMapper _mapper;
      private IClientDATARepository _clientDATARepository;
      private readonly IClientServices _clientServices;
      private readonly DATAContext _context;
  
      public ODataClientController(IMapper mapper, IClientDATARepository clientDATARepository, IClientServices clientServices, DATAContext context) {
          _mapper = mapper;
          _clientDATARepository = clientDATARepository;
          _clientServices = clientServices;
          _context = context;
      }
  
  
      [HttpGet]
      [ODataRoute("AllClients()")]
      [EnableQuery()]
      public IQueryable&lt;ClientIndexDto&gt; Get(ODataQueryOptions&lt;ClientIndexDto&gt; options) 
      {
          var clients = _clientDATARepository.AllIncluding();
          var clientIndexDtos = clients.ProjectTo&lt;ClientIndexDto&gt;(_mapper);  // magic happens here...
  
          return (IQueryable&lt;ClientIndexDto&gt;)options.ApplyTo(clientIndexDtos);
      }
  </code></pre>
  
  <p>Now I get the error:</p>
  
  <pre><code>cannot convert from 'AutoMapper.IMapper' to 'AutoMapper.IConfigurationProvider
  </code></pre>
  
  <p>on the line:</p>
  
  <pre><code>var clientIndexDtos = clients.ProjectTo&lt;ClientIndexDto&gt;(_mapper);
  </code></pre>