Search code examples
asp.net-coreaspnetboilerplate

How to override the AbpUserConfigurationController?


I don't know the underlying principle of the AbpUserConfigurationController? How does it inject into the aspnet core DI container? Why can't it be seen on the Swagger page? I'm using the aspnetboilerplate Premium Startup Templates.


Solution

  • To override AbpUserConfigurationController

    you can use the approach mentioned in aspnetboilerplate/#3296(comment)

    To understand how Abp inject controller into AspNetCore project

    It is explained by @tseng , controller can be added via AddApplicationPart of ApplicationPartManager.

    There are a few places that Abp uses ApplicationPartManager to include additional controllers.

    1. In Abp.AspNetCore, as pointed out by @tseng, at AbpAspNetCoreModule#L47-78, the implementation here is to include Controller created in the Abp.AspNetCore assembly.

    2. In the downloaded template, you can look for *WebCoreModule.cs under *.*.Web.Core project. The following code snippet is another place that Abp converts all the application services in the MyProjectApplicationModule assembly into controllers.

    Configuration.Modules.AbpAspNetCore()
          .CreateControllersForAppServices(
              typeof(MyProjectApplicationModule).GetAssembly()
          );
    

    Also you take a look at AbpAspNetCoreConfiguration.cs#L47-L55 where the ControllerAssemblySettings is being updated.

    Take note that CreateControllersForAppServices is called in PreInitialize() of AbpModule and AddApplicationParts is called in PostInitialize() of AbpAspNetCoreModule.

    Therefore, the ControllerAssemblySettings used in the method AddApplicationParts of AbpAspNetCoreModule has already contains all the controllers to be added via ApplicationPartManager

    To understand why AbpUserConfigurationController not showing up in swagger-ui

    In short, conventional routing is not supported by Swagger, see swashbuckle-apiexplorer-and-routing.

    TokenAuthController showed up in the swagger-ui because it is decorated with [Route("api/[controller]/[action]")] (attribute routing)