Asp.Net Core 5 Registering Controllers using Application Parts

Viewed 401

I am working on a project using Asp.net core web api, in my solution I have multiple projects and each project has its own controllers classes. I added a controller class Named AccountController and registered it using a application part and it registered the controller as a application part but I have other controller class Profile Controller it does not registering.

public static IServiceCollection AddAuthenticationControllers(this IServiceCollection services)
    {
        services.AddControllers().AddApplicationPart(typeof(ProfileControllers).Assembly);
        
        services.AddControllers().AddApplicationPart(typeof(AccountControllers).Assembly);
        

        return services;
    }

Following is result of debugging of above lines.

Debugging result of profilecontroller assembly

Debbuging result of AccountController assembly

in image 2 it can be seen Account controller assembly result is red. when i hit the the api of accountcontroller from postman it successfully executes but when i hit the api of profilecontroller it gives 404 error.

1 Answers

Try this:

services.AddControllers()
   .AddApplicationPart(typeof(ProfileControllers).Assembly)
   .AddApplicationPart(typeof(AccountControllers).Assembly);
Related