这里我使用
[HttpPost]
public async Task<IActionResult> Login(LoginRequest request)
{
var user = await _userService.GetUserByEmail(request.Email);
GetUserByEmail方法无法识别是否明确存在depsite
public async Task<User> GetUserByEmail(string email)
{
return await _context.Users.FirstOrDefaultAsync(u => u.Email == email);
}
我试着用微软的建议修复它,出于某种原因,它试图在IUserService中构建方法,提醒你,_userService是UserService的一个示例我该如何修复这个问题?谢谢
编辑,为了准确这里是完整的错误脚本
Severity Code Description Project File Line Suppression State
Error CS1061 'UserService' does not contain a definition for 'GetUserByEmail' and no accessible extension method 'GetUserByEmail' accepting a first argument of type 'UserService' could be found (are you missing a using directive or an assembly reference?) LuxusCoffee2.0 C:\Users\User\source\repos\LuxusCoffee2.0\Controllers\LoginController.cs 25 Active
每次请求编辑2个
namespace LuxusCoffee2._0.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class LoginController : ControllerBase
{
private readonly UserService _userService;
public LoginController(UserService userService)
{
_userService = userService;
}
[HttpPost]
public async Task<IActionResult> Login(LoginRequest request)
{
var user = await _userService.GetUserByEmail(request.Email);
if (user == null)
{
return BadRequest("Email or password is incorrect.");
}
1条答案
按热度按时间py49o6xq1#
因此,我在IUserService.cs中是哑的,似乎我已经定义了一个从
IUserService
继承的UserService
,它无法识别UserService
中的方法的原因是因为它使用了IUserService
中的UserService
IUserService.cs
UserService.cs
我通过删除
UserService.cs
并将缺少的方法添加到IUserService.cs
中的UserService
来修复它IUserService.cs
我是哑巴,你很聪明,泰