I am working with one legacy .NET MVC project left by my colleague, he uses Microsoft Identity System to deal with user authentication. In the LoginController:
var user = userManager.FindByEmail(modelUserName);
if(user == null)
{
// the user was not found..
}
else
{}
Later I realized that FindByEmail() is actually a precompiled function written by Microsoft in the UserManagerExtension class. However, my colleague also defines another similar function called FindByEmailAsync() in his customized UserManager class:
public Task<User> FindByEmailAsync(string email)
{
return ..
}
and when I debug the project, I found the code in LoginController somehow called FindByEmailAsync() when it run "var user = userManager.FindByEmail(modelUserName)", why is that?
As you said, FindByEmail
is an extension method. Only this is a thin wrapper that just calls FindByEmailAsync
in a sync manner - easy to inspect the original source code - search for "FindByEmail" on the page.
So there is no surprise you see async method called when you actually call sync version in your code.