【发布时间】:2018-08-30 13:34:41
【问题描述】:
我正在查看核心用户身份并试图了解对象是如何被注入到 Account Controller 构造函数中的。当调用下面的构造函数时,对象已经通过依赖注入实例化了。它是在 StartUp 类“ConfigureServices”services.AddIdentity 本身期间完成的吗?你能解释一下吗?
帐户控制器
public class AccountController : Controller
{
private readonly SignInManager<ApplicationUser> _signInManager;
private readonly RoleManager<IdentityRole> _roleManager;
public AccountController(SignInManager<ApplicationUser> signInManager, RoleManager<IdentityRole> roleManager)
{
_signInManager = signInManager;
_roleManager = roleManager;
}
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<AppDbContext>()
.AddDefaultTokenProviders();
【问题讨论】:
标签: asp.net-core asp.net-core-identity