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()))
{
}
上面的代码运行时就是
相关文档:
——灵活运用 Form 表单认证中的 deny 与 allow 及保护 .htm 等文件
作者:寒羽枫(cityhunter172)
第二部分 Form 认证的实战运用
话说上回,简单地说了一下 Form 表单认证的用法。或许大家觉得太简单,对那些大内高手来说应该是“洒洒水啦”“小 Kiss 啦(小意思)”。今天咱们来点 ......
这个是在网上找的一个关于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 ......