title: Pass UserManager to an AuthorizationHandler in ConfigureServices MVC 6
body: <p>Given the following class with DI for UserManager</p>
  
  <pre class="lang-cs prettyprint-override"><code>public class AccountAuthorizationHandler : AuthorizationHandler&lt;OperationAuthorizationRequirement, AuthorisedAccount&gt;
  {
      private readonly UserManager&lt;ApplicationUser&gt; userManager;
      public AccountAuthorizationHandler(UserManager&lt;ApplicationUser&gt; userManager)
      {
          this.userManager = userManager;
      }
      protected override void Handle(AuthorizationContext context,
                                     OperationAuthorizationRequirement requirement,
                                     AuthorisedAccount resource)
      {
          // Pull the user ID claim out from the context.User
          var userId = context.User.GetUserId();
          // Get the current user's account numbers.       
          var user = userManager.Users
              .Include(u =&gt; u.AuthorisedAccounts)
              .Where(u =&gt; u.Id == userId)
              .FirstOrDefault();
  
          //Now check if the user's account numbers match the resource accountNumber, and 
          foreach( var authorizedAccount in user.AuthorisedAccounts)
          { 
              if ((resource.AccountNo == authorizedAccount.AccountNo) &amp;&amp;
                  (requirement == Operations.Read))
              context.Succeed(requirement);
          }
  
      }
  }
  </code></pre>
  
  <p>I want to instantiate it in <code>ConfigureServices</code> but it looks like I need to provide Usermanager.  ie the responsibility seem to come back to the caller.</p>
  
  <pre class="lang-cs prettyprint-override"><code>services.AddInstance&lt;IAuthorizationHandler&gt;
      (new AccountAuthorizationHandler(I want to add UserManager here));
  </code></pre>
  
  <p>I guess I thought magically the AuthorizationHandler would resolve the Dependency itself</p>
  
  <p>How to I go about this</p>
  
  <p>Thanks</p>