Upload
chris-hefley
View
4.858
Download
5
Embed Size (px)
DESCRIPTION
ASP.Net MVC: Patterns and AntiPatterns. Presentation from Devlink 2009, Nashville, TN, Chris Hefley http://indomitablehef.com
Citation preview
ASP.Net MVC : Patterns and AntiPatterns
Chris Hefley, Bandit Software
Blog: http://indomitablehef.comEmail: [email protected]
Twitter: @indomitablehef
Model View Controller
HttpRequestASP.Net
ISAPI filter
HttpModules and
HttpHandlers
Some Class
RequestRouted
To
System.Web.UI.PageSystem.Web.Mvc.ControllerSome Model Retrieve Data from
Some View
Render
Anemic Controller
“Skinny Controller, Fat Model”
GOOD
Magic Strings BAD
ASP.Net MVC Magic Strings
Banishing Magic Strings: ViewsInstead of:
Use:
Banishing Magic Strings: Controllers
Banishing Magic Strings: Controllers
One Action, One View GOODInstead of:
One Action, One View
Do this:
View Models GOOD
ViewData Dictionary BAD
ViewModel Base ClassInstead of ViewData Dictionary:
GOOD
ViewModel Base Class
Instead:
Use MVC Contrib w00t!
JavaScript in Views BAD
If you must:
More goodness from MVC Contrib:
Branching Logic in Views BAD
Or even this:
Don’t do this:
Branching Logic in Views
Branching Logic in Views
HttpContext BAD
IOC Container GOOD
IOC Container
Extensions to HtmlHelper GOOD
DataBinding to Domain Object BAD
Custom ActionResult GOOD
Miscellaneous
• Use Html.Encode• jQuery!• Use AcceptVerbs Attribute on Controller
Methods (POST for those that modify Data)• Use ASP.Net MVC to create REST-ful APIs• Extension Methods to UrlHelper• Make good use of ActionFilters
After-Market Parts GOOD
Spark View Engine• Sparkviewengine.com
S#arp Architecture
Questions?
Chris Hefley, Bandit Software
Blog: http://indomitablehef.comEmail: [email protected]
Twitter: @indomitablehef