简体   繁体   中英

2 constructors in Asp.Net Identity AccountController

In the new project template for for ASP.NET MVC 5, there are 2 constructors for Account and Manage controllers.

public AccountController()
    {
    }

public AccountController(ApplicationUserManager userManager, ApplicationSignInManager signInManager)
    {
        UserManager = userManager;
        SignInManager = signInManager;
    }

I'm initializing some properties in the constructor and I've been initially confused which one to use. When stepping through the code I see only the first default constructor is ever called.

I'm wondering whether the 2nd controller is only a placeholder for Dependency Injection, which I'm not using currently. Or could Identity ever be calling it in the background for some other purposes when DI is not used? (I'm figuring based on going through the framework, that both UserManager and SignInManager are already built in Startup, so there should be no need to recreate them in the second constructor).

The first constructor is there to not let the second one override it. I am not sure the first one has some internal use for Asp.Net Identity or not but definitely they wanted to keep that for some reasons and not let it be override.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM