I have the problem presented below and I do not know how to solve it, the system is complaining that it can not access my IAuthentication class.
The following error appears below.
Belowmycontroller'scode
usingSystem.Linq;usingSystem.Threading.Tasks;usingMeuConsultorio.Domain.Account;usingMeuConsultorio.Web.ViewsModels.Account;usingMicrosoft.AspNetCore.Http;usingMicrosoft.AspNetCore.Mvc;usingMicrosoft.Extensions.Logging;namespaceMeuConsultorio.Web.Controllers{publicclassAccountController:Controller{privatereadonlyIAuthentication_authentication;privatereadonlyIManager_manager;privatereadonlyILogger_logger;publicAccountController(IAuthenticationauthentication,IManagermanager,ILogger<AccountController>logger){_authentication=authentication;_manager=manager;_logger=logger;}//GET:AccountpublicIActionResultIndex(){varusers=_manager.ListAll();varuserViewModel=users.Select(u=>newUserViewModel{Id=u.Id,Email=u.Email});returnView();}//GET:Account/Details/5publicActionResultDetails(intid){returnView();}//GET:Account/CreatepublicIActionResultRegister(){returnView();}//POST:Account/Create[HttpPost][ValidateAntiForgeryToken]publicasyncTask<IActionResult>Register(RegisterViewModelviewModel){await_manager.CreateAsync(viewModel.Email,viewModel.Password,viewModel.Role);returnOk();//try//{////TODO:Addinsertlogichere//await_manager.CreateAsync(viewModel.Email,viewModel.Password,viewModel.Role);//returnRedirectToAction(nameof(Index));//}//catch//{//returnView();//}}publicIActionResultLogin(){returnView();}[HttpPost]publicasyncTask<IActionResult>Login(LoginViewModellogin){varresult=await_authentication.Authenticate(login.UserName,login.Password);if(result)returnRedirect("index");
else
{
ModelState.AddModelError(string.Empty, "Login inválido");
return View(login);
}
}
// GET: Account/Edit/5
public ActionResult Edit(int id)
{
return View();
}
// POST: Account/Edit/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(int id, IFormCollection collection)
{
try
{
// TODO: Add update logic here
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
// GET: Account/Delete/5
public ActionResult Delete(int id)
{
return View();
}
// POST: Account/Delete/5
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Delete(int id, IFormCollection collection)
{
try
{
// TODO: Add delete logic here
return RedirectToAction(nameof(Index));
}
catch
{
return View();
}
}
}
}
And below my IAuthentication code
using System.Threading.Tasks;
namespace MeuConsultorio.Domain.Account
{
public interface IAuthentication
{
Task<bool> Authenticate(string email, string password);
Task Logout();
}
}
Class Authentication where my interface is consumed.
using MeuConsultorio.Domain.Account;
using Microsoft.AspNetCore.Identity;
using System.Threading.Tasks;
namespace MeuConsultorio.Data.Identity
{
public class Authentication : IAuthentication
{
private readonly SignInManager<ApplicationUser> _signInManager;
public Authentication(SignInManager<ApplicationUser> signInManager)
{
_signInManager = signInManager;
}
public async Task<bool> Authenticate(string email, string password)
{
var result = await _signInManager.PasswordSignInAsync(email, password, false, lockoutOnFailure: false);
return result.Succeeded;
}
public async Task Logout()
{
await _signInManager.SignOutAsync();
}
}
}