我的对象是否在 ConfigureServices 的 AddIdentity 启动期间实例化 class?

Are my objects instantiated during ConfigureServices' AddIdentity startup class?

我正在研究核心用户身份,并试图了解该对象是如何注入到帐户控制器构造函数中的。当调用下面的构造函数时,对象已经通过依赖注入实例化了。它是在 StartUp class "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();

你是对的,AddIdentity method is responsible for setting up the services. You can see this for yourself if you look at the code,这是一个小片段:

//etc...
services.TryAddScoped<UserManager<TUser>>();
services.TryAddScoped<SignInManager<TUser>>();
services.TryAddScoped<RoleManager<TRole>>();
//etc...