I have tried various ways to get my application to work and have tried searching here for a solution to the various messages that I received but none have worked. So, I decided to start from scratch and ask for the proper way to connect my 2 applications.
I have a Solution with 2 projects inside it:
Application
Application is a stand alone app that has login/logout, user management capabilities etc.
Application is connected to a databaseApplicationApi
ApplicationApi is a console application that references Application
ApplicationApi's main task is to receive any incoming requests via its ApiController and then pass that to Application who will then return a result to it
ApplicationApi is not connected to a database
This is the function in ApplicationApi that I want to call a function in Application
namespace ApplicationApi.Controllers
{
public class TokenController:ApiController
{
public String Get()
{
var auth = new AuthenticationController();
return auth.AuthenticateUser("user@one.com", "P@ssw0rd").ToString();
}
}
}
This is the function that is called by ApplicationApi
namespace Application.Controllers.API
{
public class AuthenticationController : Controller
{
ApplicationDbContext dbContext = new ApplicationDbContext();
Logger log = LogManager.GetCurrentClassLogger();
PasswordHasher passwordHasher = new PasswordHasher();
public bool AuthenticateUser(String username, String password)
{
try
{
var user = dbContext.Users.FirstOrDefault(u => u.UserName == username);
if (user == null)
{
log.Error(username + " not found");
return false;
}
else
{
var result = passwordHasher.VerifyHashedPassword(user.PasswordHash, password);
if (result == PasswordVerificationResult.Success)
{
return true;
}
else
{
log.Error("Invalid password for user: " + username);
return false;
}
}
}
catch (Exception e)
{
log.Error(e, "Exception found for user: " + username);
return false;
}
}
}
}
At the moment, when I make a request from Postman, I get this error from Application when debug is on:
{"No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information."}
This looks like its saying that my ApplicationApi needs to have EntityFramework or needs to refer to it to work?
That is where I get confused. ApplicationApi is only supposed to ask Application for a result. Why does this error happen? ApplicationApi does not have any database connections. Nor does it need to to. Its only a transport layer.
Maybe I've started wrong so I hope someone can guide me on how to actually do this.
EDIT: My question is not a duplicate of that one because I'm asking why I need EntityFramework in an Api Project that won't connect to a database?