Is it better to use Automapper in controller or repository pattern?
<p>What is the correct way of using Automapper? Is it in controller or is it in repository pattern? To me it seems like putting them in controller is not neat and unorganized.</p>

<p>So for example, </p>

<p>(Automapper used in controller):</p>

<p><strong>- StudentController</strong></p>

<pre><code>public IActionResult Get()
    {           
        var query = _context.Students.ToList();

        var mapper = AutoMapper.Mapper.Map&lt;List&lt;Student&gt;, List&lt;StudentViewModel&gt;&gt;(query);

        return new OkObjectResult(mapper);
    }
</code></pre>

<p>(Automapper used in repository pattern):</p>

<p><strong>- StudentController</strong></p>

<pre><code>public IActionResult Get()
    {          
        return new OkObjectResult(_studentRepository.GetAllStudents());       
    }
</code></pre>

<p><strong>- StudentRepository</strong></p>

<pre><code>public IEnumerable&lt;StudentViewModel&gt; GetAllStudents()
    {
       var query = _context.Students.ToList();

        var mapper = AutoMapper.Mapper.Map&lt;List&lt;Student&gt;, List&lt;StudentViewModel&gt;&gt;(query);

        return mapper;
    }
</code></pre>

<p>Which returns the same result, but what is actually the best place to put automapper settings? and also would it be better to use <strong>.ProjectTo()</strong> to avoid using <strong>AutoMapper.Mapper.Map</strong>?</p>