title: How to conditionally map/ignore properties based on user role in AutoMapper in asp.net core
body: <p>I'm using <code>AutoMapper.Extensions.Microsoft.DependencyInjection 7.0.0</code></p>
  
  <p>I need to map properties only for user with specific roles else ignore the mapping using automapper in my asp.net core 3.0 project.</p>
  
  <p>Here is what I tried,</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class BranchProfile : Profile
  {
      private readonly HttpContext _httpContext;
  
      public BranchProfile(IHttpContextAccessor httpContextAccessor)
      {
          _httpContext = httpContextAccessor.HttpContext;
  
          CreateMap&lt;Branch, BranchEditViewModel&gt;()
              .ForMember(dest =&gt; dest.Lock, opt =&gt; opt.Condition(src =&gt; _httpContext.User.IsInRole(UserRoles.Master.ToString())))
              .ForMember(dest =&gt; dest.ExpireOn, opt =&gt; opt.Condition(src =&gt; _httpContext.User.IsInRole(UserRoles.Master.ToString())));
      }
  }
  </code></pre>
  
  <p>But I get the following no parameter less constructor exception.</p>
  
  <blockquote>
    <p>No parameterless constructor defined for type 'BranchProfile'</p>
  </blockquote>
  
  <p>Any better way to access <code>HttpContext</code> to do this conditional mapping? Please assist</p>