title: Can I use ASP.NET Core authorization in a WebAPI2 REST API?
body: <p>I am building a new Web API 2 based RESTful API.  (I have to target the full framework due to some dependencies in the solution).</p>
  
  <p>I have in the past used System.Security.Claims.ClaimAuthorizationManager to build in custom user security checks. This solution however is not very test friendly (DI) or async enabled.</p>
  
  <p>I would like to use the Policy-based authorization available in aspnet core (<a href="https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/aspnet/core/security/authorization/policies</a>) as this seems to be a great model that fit my needs perfectly.</p>
  
  <p>I am however stuck as to whether or not this is actually possible for not.  It seems that the real technical sticking point may be that the policy requirement finds the requirement handler through registration of the handler in the services collection, for example:</p>
  
  <pre><code>public void ConfigureServices(IServiceCollection services)
  {
      services.AddMvc();
  
      services.AddAuthorization(options =&gt;
      {
          options.AddPolicy("AtLeast21", policy =&gt;
              policy.Requirements.Add(new MinimumAgeRequirement(21)));
      });
  
      services.AddSingleton&lt;IAuthorizationHandler, MinimumAgeHandler&gt;();
  }
  </code></pre>
  
  <p>Is there any way to get the requirement handler to be picked up by the authorization service in a Web API 2 service?</p>