asp.net-mvc – 为什么MVC提供的Default AccountController中有2
发布时间:2020-12-16 09:31:19 所属栏目:asp.Net 来源:网络整理
导读:这是框架生成的默认AccountController.cs. public class AccountController : Controller{ public IFormsAuthentication FormsAuth { get; private set; } public IMembershipService MembershipService { get; private set; } public AccountController() :
这是框架生成的默认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) { } 他们似乎在其他两个地方使用这种类型的构造函数. 谢谢你的帮助 解决方法
这实际上是Bastard Injection反模式的实现.
我们的想法是支持构造函数注入以允许依赖注入(DI),同时仍为默认行为提供默认构造函数. 实际上没有必要使用默认构造函数,但如果省略它,则必须提供自定义IControllerFactory,因为DefaultControllerFactory假定所有控制器都具有默认构造函数. ASP.NET MVC在构建时考虑了DI,但我想为了保持简单,Bastard Injection模式用于项目模板,以避免强制开发人员使用特定的IControllerFactory. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net – 如何在ModalPopupExtender前显示CalendarExtend
- asp.net – IIS中的自定义虚拟路径提供程序
- asp.net-mvc – 启用relaxedUrlToFileSystemMapping以允许以
- asp.net – Visual Studio开发服务器(2010)和NTLM授权
- Godaddy ASP.NET会员数据库困境
- MVC3 .NET会话随机丢失会话值并返回null
- .net core中的对象池
- asp.net – Datareader,DataAdapter,Dataset,DataView之间的
- asp.net-mvc – 使用Asp.Net Mvc进行AngularJs路由
- ASP.NET Web Pages - 对象
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC 2 RC区域和共享模型
- asp.net-mvc-2 – 使用.Net Framework 4.0的Shar
- asp.net – 最佳实践:DataBound with loop vs R
- 腾讯云-容器-mysql搭建_进入退出和常用查询
- 使用asp.net必填字段验证器和两个复选框
- asp.net – 未定义JSONP回调方法
- asp-classic – 我使用经典的ASP,IIS6和WinServe
- asp.net – 从ASP启动/停止服务. NET页面
- asp.net-mvc – 将部分视图渲染为字符串MVC4
- asp.net – 如何自定义UseExternalSignInCookie?
热点阅读