Using StructureMap with the ASP.NET MVC framework
原文地址:http://www.bengtbe.com/blog/post/2009/02/27/Using-StructureMap-with-the-ASPNET-MVC-framework.aspx
Using StructureMap with the ASP.NET MVC framework
2009-02-27 星期五 作者:bengtbe
在这里我要阐述的是怎么用.net frameword 框架下的StructureMap这个类.
在学习这个之间你需要对ASP.NET MVC框架,依赖注入和控制反转有基本的了解。
这些技术也不只用于 StructureMap ,如果你喜欢这些,那么你当然也用其它的DI/Ioc 工具了。
我们就用这个UserController 例子还说起,它有一个属性IUserService 来调用控制层的服务,当
然IUserService 本身也会调用 IUserPepository 这个在数据层的方法。这个UserController 用
控制反转来访问IUserService ,这就是说这个UserService 类就是选用控制反转来注入
UserController 实例化IUserService;
public class UserController : Controller
{
private readonly IUserService m_UserService;
public UserController(IUserService userService)
{
m_UserService = userService;
}
public ActionResult Edit(int id)
{
return View(m_UserService.GetById(id));
}
}
这就叫容器注入,如果你就这样写而没有写其它的配置文件那么你将得到如下的错误:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web
request. Please review the stack trace for more information about the error and where
it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined
for this object.
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
其实默认的,这个ASP.NET MVC framework 是需要一个构造函数的,一种方法是构造形式如下:
public UserController() : this(new UserService(new UserRepository()))
{
}
上面的代码运行时就是
相关文档:
在开发需要用户注册后才能使用提供的各项功能的应用程序时,在新用户提交注册信息后,较常见的做法是由程序生成随机密码,然后发送密码到用户注册时填写的电子信箱,用户再用收到的密码来激活其帐户。
实现ASP.NET生成随机密码功能是很容易的,下面的代码给出了完整的实现方法:
publicstaticstringMakePassword(st ......
首先建立一个c/s程序 在新建的form上加入一个浏览器控件和一个时间控件浏览器控件能转向你要执行的页面而时间控件控制多少时间后关闭你要执行的页面然后设置form的visible为false form的状态为最小化 目的是将整个执行的页面程序包在form的浏览器控件中执行而form会被隐藏 这样做神不知鬼不觉。最后用windows的计划任务每天 ......
这个是在网上找的一个关于ASP.NET MVC 的定义,我觉得已经解释的够好了,所以就借过来用用了 ,呵呵
希望有心学习ASP.NET MVC 的朋友先熟悉定义,在后续的文章中会更轻松的学习ASP.NET MVC
下面我们一起踏上ASP.NET MVC 之旅吧,只要有恒心和毅力,祝学者们旅途愉快!
The Model-View-Controller (MVC) architectu ......
转贴自 http://wuxiong8665.blog.163.com/blog/static/93512200991811400157/
概览:
文件夹名称
文件类型
注 释
Bin
.dll
包含应用程序所需的任何预生成的程序集
App_Browsers
&n ......
在webconfig中有一个重要节点 <system.web> 其中包括了一个身份验证配置节点
<authentication mode="Windows"/>
其中 authentication 是节点名,mode是模式,上述代码表示 采用windows身份验证,那么此时身份验证将交给iis处理,而iis中默认设
<authentication mode="Forms" >
&n ......