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()))
{
}
ÉÏÃæµÄ´úÂëÔËÐÐʱ¾ÍÊÇ
Ïà¹ØÎĵµ£º
[Òë]µÚÒ»Õ ½éÉÜ Web ÃÅ»§ÒÔ¼° Dropthings.com
ÔÚÕâ±¾ÊéÖУ¬ÎÒ½«»á¸øÄúչʾÔõÑù½éÉÜÒ»¸ö Ajax£¬Web 2.0 ʽµÄÃÅ»§¡£Õâ¸öÃÅ»§Ê¹Óà ASP.NET 3.5 , ASP.NET AJAX ºÍ .NET 3.5 , ҲʹÓÃÁË LINQ ºÍ SQL Server 2005.ÔÚ´´½¨Ó¦ÓóÌÐòÖУ¬Äã¿ÉÒÔÁ˽⵽£º
±ØÐëÒª×öµÄÉè¼Æ¾ö¶¨ºÍ Web 2.0 Óû§½çÃæÖпÉÓÃÐÔµÄÎÊÌâ
¼Ü¹¹µÄ¸´ÔÓÐԺͷ ......
×÷Õߣºº®Óð·ã(cityhunter172)
Ðò
´úÂëд N ¾ÃÁË£¬×ÜÏëдµÃ±ðµÄ¡£Õâ²»£¬ÉÏͷ˵ÔÚÕûºÏÁ½¸öÏîÄ¿£¬×ö³Éµ¥Ò»µÇ¼£¨Single Sign On£©£¬Ò²ÓÐÈ˳Æ֮Ϊ“µ¥µãµÇ¼”¡£²éÔÄÏà¹ØÎĵµºó£¬ÖÕÓÚʵÏÖÁË£¬ÏÖÔÚ°ÑËüÄóöÀ´Óë´ó¼ÒÒ»Æð·ÖÏí¡£»òÐí´ó¼Ò»áÎÊ£º“ÕâÓë±êÌâ²»·ûѽ£¿”±ð¼±£¬ÔÚϱÊ֮ǰ£¬ÎÒÄÔ×ÓÀïÏëµ½ÁËÎÒ¸ÕʹÓà ......
1.»ñÈ¡Return·µ»ØÖµ
³ÌÐò´úÂë//´æ´¢¹ý³Ì
//Create PROCEDURE MYSQL
// @a int,
// @b int
//AS
// return @a + @b
//GO
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalSqlServer"].ToStri ......
Õâ¸öÊÇÔÚÍøÉÏÕÒµÄÒ»¸ö¹ØÓÚASP.NET MVC µÄ¶¨Ò壬ÎÒ¾õµÃÒѾ½âÊ͵Ĺ»ºÃÁË£¬ËùÒԾͽè¹ýÀ´ÓÃÓÃÁË £¬ºÇºÇ
Ï£ÍûÓÐÐÄѧϰASP.NET MVC µÄÅóÓÑÏÈÊìϤ¶¨Ò壬ÔÚºóÐøµÄÎÄÕÂÖлá¸üÇáËɵÄѧϰASP.NET MVC
ÏÂÃæÎÒÃÇÒ»Æð̤ÉÏASP.NET MVC Ö®Âðɣ¬Ö»ÒªÓкãÐĺÍÒãÁ¦£¬×£Ñ§ÕßÃÇÂÃ;Óä¿ì£¡
The Model-View-Controller (MVC) architectu ......