我对如何从asp.net标识模板执行代码感到困惑。Asp.Net身份的Owin上下文
private ApplicationSignInManager _signInManager;
private ApplicationUserManager _userManager;
private ApplicationRoleManager _roleManager;
public AuthController() { }
public AuthController(ApplicationUserManager userManager, ApplicationSignInManager signInManager, ApplicationRoleManager roleManager)
{
UserManager = userManager;
SignInManager = signInManager;
RoleManager = roleManager;
}
public ApplicationRoleManager RoleManager
{
get { return _roleManager ?? HttpContext.GetOwinContext().Get<ApplicationRoleManager>(); }
private set { _roleManager = value; }
}
public ApplicationSignInManager SignInManager
{
get { return _signInManager ?? HttpContext.GetOwinContext().Get<ApplicationSignInManager>(); }
private set { _signInManager = value; }
}
public ApplicationUserManager UserManager
{
get { return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
private set { _userManager = value; }
}
为什么我们有带参数的AuthController?依赖注入的目的?如果没有发生注射,则调用在Startup.cs上指定的owincontext?这是否意味着我们可以忽略owincontext并仅使用注入?
而当我试图调试这是如何运行,它只是通过无参数的构造函数,它打破了我的代码。这个参数化构造函数没有被使用吗?
有什么想法?谢谢。