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.
My upload controller looks something like this
namespace MyNamespace
{
[Authorize("PolicyName")]
[Route("Upload")]
public class UploadController : Controller
{
[HttpPost]
[Route("Upload")]
public async Task<IActionResult> Upload(UploadModel model)
{
// impl..
return Ok();
}
}
}
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?
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?
My idea of an api would be like..
((IApplicationBuilder)app).UseUploadController(config => {
config.PolicyName = "Whatever",
config.UploadRoute = "UploadStuff"
});
... 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.
Anyone got any pointers or libraries to look at for inspiration?