0

System.InvalidOperationException: Unable to resolve service for type 'Pwc.EMSWebapi.IUserManagementService' while attempting to activate 'Pwc.EMSWebapi.UserManagementController'. at lambda_method3(Closure, IServiceProvider, Object[]) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)

I added below in program.cs file:-

` services.AddTransient<IUserManagementRepoitory, UserManagementRepoitory>();
    services.AddTransient<IUserManagementService, UserManagementService>();`
I tried below in program.cs file:-
` services.AddTransient<IUserManagementRepoitory, UserManagementRepoitory>();
    services.AddTransient<IUserManagementService, UserManagementService>();`
 `services.AddScoped<IUserManagementService, UserManagementService>();`

Edit:-

my controller

public 

    UserManagementController(IUserManagementService userManagementService)
            {
                this._userManagementService = userManagementService;
                //this.applicationUser = applicationUser;
            //this.user = user;
        }

service:-

public

UserManagementService(IUserManagementRepository userManagementRepoitory)
        {
            this._userManagementRepoitory = userManagementRepoitory;
        }

Repository

 public UserManagementRepoitory(EMSDbContext bcDbContext, IUser user)
        {
            this.dbContext = bcDbContext;
            this.user = user;
        }
3
  • There is nothing wrong with this part of the code you provided, please provide a minimal reproducible example. Commented Jul 21, 2023 at 8:49
  • The most likely cause of this error is because there exists a second type in the application that is named IUserManagementService. Check if the type referenced by the controller is the same type as registered in the program.cs. If you are using Visual Studio as your IDE, you can set the cursor on the type name and press F12. This will jump to the implementation. Commented Jul 25, 2023 at 18:56
  • btw, the code samples are really badly formatted. You should consider posting better formatted code examples the next time you raise a question. If you want others to spend their spare time on answering your questions, you should invest in making it as easy as possible for them to answer your question. Commented Jul 25, 2023 at 18:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.