System.InvalidOperationException:尝试激活“Pwc.EMSWebapi.UserManagementController”时无法解析类型“Pwc.EMSWebapi.IUserManagementService”的服务。 at lambda_method3(Closure, IServiceProvider, Object[]) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass6_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
我在program.cs文件中添加了以下内容:-
` 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:-
我的控制器
public
UserManagementController(IUserManagementService userManagementService)
{
this._userManagementService = userManagementService;
//this.applicationUser = applicationUser;
//this.user = user;
}
服务:-
public
UserManagementService(IUserManagementRepository userManagementRepoitory)
{
this._userManagementRepoitory = userManagementRepoitory;
}
存储库
public UserManagementRepoitory(EMSDbContext bcDbContext, IUser user)
{
this.dbContext = bcDbContext;
this.user = user;
}