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;
}
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 pressF12. This will jump to the implementation.