2

I have a module/project which contains several controllers (API) for various tasks. I use this module in other applications. The problem is that the application registers all controllers even from sub-modules.

services.AddControllers()

Is there a way to control this behavior? Note I'm not talking about controller activation. Also I'm fine with automatic registration from application's module. However I would like to manually register my sub-module's controllers. By this I could register only few controllers from my sub-module needed by my application.

Thanks :-)

Csaba
  • 301
  • 3
  • 11
  • Which version are you using? Check this thread that may shed some light: https://stackoverflow.com/questions/47617994/how-to-use-a-controller-in-another-assembly-in-asp-net-core-mvc-2-0/47618058 – Lia Jun 03 '21 at 02:56
  • I'm using .Net Core 5. The all controllers are registered/added automatically. However I would like to have some control over it e.g. some attribute to controller [ManualRegistered] which cause that the controller is not registered automatically instead I have to do something like service.AddController() – Csaba Jun 03 '21 at 04:56
  • There doesn't seem to be any built in attributes to what you need. It's suggested to check Action Filters which you can do your customization before you get into your controller. Details can be found in: https://learn.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-5.0 – Lia Jun 07 '21 at 01:52

0 Answers0