If you want to include internal controllers, you can provide your own implementation of the ControllerFeatureProvider
class which is responsible for determining whether a type is a controller or not. In the following example I have created an implementation that looks for controllers implementing a custom base class and falling back to the default implementation for all other cases. In this case, the custom controllers will be discoverable despite being internal, while all other controllers will not.
class CustomControllerFeatureProvider : ControllerFeatureProvider
{
protected override bool IsController(TypeInfo typeInfo)
{
var isCustomController = !typeInfo.IsAbstract && typeof(MyCustomControllerBase).IsAssignableFrom(typeInfo);
return isCustomController || base.IsController(typeInfo);
}
}
and to register it:
services.AddMvc().ConfigureApplicationPartManager(manager =>
{
manager.FeatureProviders.Add(new CustomControllerFeatureProvider());
});
You should probably take a look at the implementation of IsController
to see how ASP.NET handles edge cases around the types.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…