Unfortunately, I can't find a solution that fits my requirements, so I decided to create a new question. I know how to create an Controller in asp and configure its route, roles and policy using DataAnnotations like the following example:
[ApiController]
[Route("api/[Controller]")]
[Route("/delete/{id}")]
[Authorize(Roles = "MyRole", Policy = "MyPolicy")]
public class ConcreteController : ControllerBase
{
//...
}
But I'm searching for a way to register & configure controllers within a single function. Something like the sample bellow.
public void RegisterControllers(IServiceCollection services)
{
services.AddController(typeof(GenericController<MyModel>), new ControllerConfig{
Route="api/custom",
Roles="MyRole",
Policy="MyPolicy"});
}
I found some posts like the following, but I don't want to solve this problem by using class-inheritance
Create a controller programmatically
ConcreteControllerisn't specified in your second piece of code. Is that intentional?