title: Create a controller programmatically
body: <p>It has been decided we should have a common upload http api across different applications. I have a file upload controller which I want to use in multiple webapi projects.</p>
  
  <p>My upload controller looks something like this</p>
  
  <pre><code>namespace MyNamespace
  {
      [Authorize("PolicyName")]
      [Route("Upload")]
      public class UploadController : Controller
      {
          [HttpPost]
          [Route("Upload")]
          public async Task&lt;IActionResult&gt; Upload(UploadModel model)
          {
               // impl..
               return Ok();
          }
      }
  }
  </code></pre>
  
  <p>Naively I thought I'd just extract this into a class library and I'd be able to register it, but I can't find how?</p>
  
  <p>Regardless, I do not think this is the correct method to use. I want to be able to configure the Authorize policy name, and potentially the routes. So I'm thinking I want to perhaps build up the controller, its routes and authorize setting and register it some how?</p>
  
  <p>My idea of an api would be like..</p>
  
  <pre><code>((IApplicationBuilder)app).UseUploadController(config =&gt; {
      config.PolicyName = "Whatever",
      config.UploadRoute = "UploadStuff"
  });
  </code></pre>
  
  <p>... this would create and register the controller. No idea where to start though. I have absolutely no clue on how controllers are discovered or if they can be registered programatically.</p>
  
  <p>Anyone got any pointers or libraries to look at for inspiration?</p>