Discovering Generic Controllers in ASP.NET Core

前端 未结 4 1576
时光取名叫无心
时光取名叫无心 2020-12-03 01:18

I am trying to create a generic controller like this:

[Route(\"api/[controller]\")]
public class OrdersController : Controller where T : IOrder
{
           


        
4条回答
  •  我在风中等你
    2020-12-03 02:01

    To get a list of controllers in RC2, just get ApplicationPartManager from DependencyInjection and do this:

        ApplicationPartManager appManager = ;
    
        var controllerFeature = new ControllerFeature();
        appManager.PopulateFeature(controllerFeature);
    
        foreach(var controller in controllerFeature.Controllers)
        {
            ...
        }
    

提交回复
热议问题