【发布时间】:2009-12-31 04:51:25
【问题描述】:
这是框架生成的默认 AccountController.cs。
public class AccountController : Controller
{
public IFormsAuthentication FormsAuth { get; private set; }
public IMembershipService MembershipService { get; private set; }
public AccountController()
: this(null, null)
{
}
public AccountController(IFormsAuthentication formsAuth, IMembershipService membershipService)
{
FormsAuth = formsAuth ?? new FormsAuthenticationService();
MembershipService = membershipService ?? new AccountMembershipService();
//---
}
这很容易理解。
public AccountController(IFormsAuthentication formsAuth,
IMembershipService membershipService)
{
FormsAuth = formsAuth ?? new FormsAuthenticationService();
MembershipService = membershipService ?? new AccountMembershipService();
}
这是什么?它的目的是什么?它是帐户控制器特有的还是其他控制器的要求?而且,我为什么要把它合并到我的项目中?
public AccountController()
: this(null, null)
{
}
他们似乎在另外两个地方使用了这种类型的构造函数。
感谢您的帮助
【问题讨论】:
标签: asp.net-mvc dependency-injection constructor